让我们说一说,当程序启动时,用户会在一行上打印他/她可以输入的内容 值,例如:
我有苹果,有梨
然后用户可以在两个“都具有”之后在两个空格中输入值
答案 0 :(得分:0)
执行此操作的基本程序应该是
input1 = input("Enter a fruit ") #Ask the user to input
input2 = input("Enter another fruit") #then ask for another
str = "I have a(n) " #store the basic string (the 'n' is in brackets because we don't know if the user input will start with a vowel or not .. you can develop this later)
str = str + input_string1 + " and" + str + input_string2 #concatenate the lot
print("Output = ", str) #this will give you "Output = "(your sentence)
print(str) #or you could just print the string
希望这会有所帮助
(这是用于接受列表/拆分/使用for循环的代码,但是您必须添加更多代码以检查是否添加了“和”,检查元音等。)
input_string = input("Enter fruits separated by a comma ")
str = "I have a(n) "
fruit_list = input_string.split(",")
#print out the result
for fruit in fruit_list:
print(str + fruit )