【发布时间】:2020-10-06 10:18:47
【问题描述】:
我真的是 python 新手,我正在尝试创建一个小型 ouija 游戏。
我有一个随机选择的数字(年龄)列表 我想将该随机选择附加到一个空列表并仅输出随机选择编号 但是,当我运行我的代码时,它会输出原始列表中的所有内容,但是 if else 似乎可以输出正确的文本,如下所述,但会列出原始列表中的每个数字
有人可以帮忙吗?
import random
#create list of random ages
age=["12,78,14,43,54,33,23,5,85,20,54,13"]
#user input
spirit2=input("Ask me how old I am: ")
#creat empty list of what will be the random age
agenum=[]
def checkage():
#generate random age from the list age
agespirit=random.choice(age)
#append the random age to the to the agenum list
agenum.append(agespirit)
#print to terminal
if "12" in agespirit:
print("I am only",agenum,"years old")
else:
print("I am",agenum,"years old")
checkage()
【问题讨论】: