简体   繁体   English

如何使用用户输入的单词创建句子

[英]how to create a sentence using words from user input

How would I create a sentence using words from user input?如何使用用户输入的单词创建句子? I have a program right now that asks the user for a number and then based on that number, the user must type in that amount of words that then are supposed to come together to make a sentence.我现在有一个程序,它要求用户输入一个数字,然后根据该数字,用户必须输入一定数量的单词,然后这些单词应该放在一起构成一个句子。 this is what I have so far:这是我到目前为止:

howmany = (int (input ("How many words?\n>")))
for words in range (howmany):
        words = input ("Words please:\n>")

give a try into this code, should work fine:试试这个代码,应该可以正常工作:

from __future__ import print_function

howmany = int (input ("How many words?\n>"))

words = []
for i in range (howmany):
    words.append(str(raw_input ("Words please:\n>")))

for word in words:
    print(word, end=' ')


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM