[英]Print word from phrase
目的是首先向用户打印文本“您的完美寒假是否包括阳光温暖的沙滩和咸海浪或鼓舞人心的城市生活?”
在此之后,它要求用户输入一个数字。 根据数字,它会从文本中打印该单词。
例如,数字 0 将是“Does”。
print(‘Does your perfect winter vacation include sun-heated beach sand and salty waves or inspiring city life?’)
phrase = ‘Does your perfect winter vacation include sun-heated beach sand and salty waves or inspiring city life?’
ask = input('Print the word from the phrase, by your given number? ')
x = ask
y = phrase.split()
for i in y()[x]:
print(i)
几个建议:
split
function 返回一个列表,因此您不能调用它( split()()
)一个简单的代码(没有健壮性)如下所示:
phrase = 'Does your perfect winter vacation include sun-heated beach sand and salty waves or inspiring city life?'
print(phrase)
x = int(input('Print the word from the phrase, by your given number? '))
y = phrase.split()
print(y[x])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.