【发布时间】:2022-09-25 09:10:43
【问题描述】:
我对编码很陌生,所以如果答案很简单,我很抱歉,但我目前正在尝试编写一个魔术 8 球游戏。我希望计算机在用户提供输入时从我制作的列表中提供一个随机字符串给用户。这是我到目前为止所做的代码:
import random
print(\"Welcome to the Magic 8 Ball Game!\")
#Create phrases the maigc 8 ball will say to the user
phrases = [\"Ask again\", \"Reply hazy, try again.\", \"I do see that in your near future...\", \"My sources say no\", \"Very possible\", \"Yes. Very soon.\"]
#Ask the user to ask a question to start the game
answer = input(\"The game has started. Ask a question.\\n\")
#Make a loop
for i in answer:
print(random.choice(phrases))
当我运行代码时,它不会给用户一个字符串,而是随机给出多个字符串。我想我可能没有正确使用 for 循环......
标签: python