有序打印,并确认以随机列表的形式进行



我有以下以前随机生成的列表:

Car
Boat
Bicycle
House
Apple

我正在尝试打印它们并确认,所以运行后会要求我确认

Car
...Y
Boat
...Y
Bicycle
...Y
House
...Y
Apple
...Y

...Y表示用户的确认。

我不知道该怎么做,所以任何提示都非常感谢。

for item in "Car Boat Bicycle House Apple".split(" "):
x = input(f"{item}n")
# do something with confirmation x

您将使用 input(( 来询问答案,然后使用它

然后,您可以检查答案:

#!/usr/local/bin/python3
list = ["Car", "Boat", "Bicycle", "House", "Apple" ]

for item in list:
answer = input(item+'?n') 
answer = "" + answer
# converting to lower case makes checking simpler
answer = answer.lower()
if (answer == 'y' or answer == 'yes'):
print("ok")
else:
print('No ' +item+  ' for you.')

最新更新