【发布时间】:2021-02-24 18:00:43
【问题描述】:
目的是首先向用户打印文本“你完美的寒假是包括阳光温暖的沙滩和咸水的海浪,还是鼓舞人心的城市生活?”
在此之后,它要求用户输入一个数字。根据数字,它会从文本中打印该单词。
例如,数字 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)
【问题讨论】:
-
1.将
x转换为数字:x = int(ask)。 2. 使用 x 作为索引:print(phrase.split()[x])。不确定循环的用途。 -
这似乎是一个家庭作业问题,而且措辞很糟糕。此外,没有提出任何问题。你有什么问题?您需要什么帮助?
标签: python for-loop input split