我的python代码有问题。我是一个初学者,所以这是一个非常简单的问题。所以我只有几个月的经验(4个月(。我正在做一个项目,其中有QnA,我在两件事上有问题。第一:我不能调用这些函数:
def questions()
def question2()
第二个问题:我想为E.G:的问题做选择
def question():
Q1 = input("Who is the lord of a random place")
if Q1 == ["Lofi", "Loafer", "Lofe"]:
print('Correct answer!!')
else:
print('Wrong answer!! The correct answer is LOFI!!')
我不确定该使用什么运算符或关键字来执行此操作。请帮忙,这是代码:
def question():
Q1 = input("Who is the lord of a random place")
if Q1 == ["Lofi", "Loafer", "Lofe"]:
print('Correct anwer!!')
else:
print('Wrong answer!! The correct answer is LOFI!!')
question()
def question2():
Q2 = input("Who is the most trustful person in the world?")
if Q2 == ["Lofi", "Annu", "scoob"]:
print("Correct answer!! U WIN!!!!")
else:
print("WRONG ANSWER!!")
question2()
你好吗?要调用函数,您应该这样做=>myfunction((
当您想调用函数时,不需要在函数前面加一个def。要调用函数,请尝试以下代码:
questions()
question2()
关于你的第二个问题,我不明白
-
您需要正确缩进程序。对函数question((和question2((的调用需要在根缩进中
-
您可以通过使用";在";关键字作为问题函数,或使用关键字";任何";如问题2中的函数
def question(): Q1 = input("Who is the lord of a random place") if Q1 in ["Lofi", "Loafer", "Lofe"]: print('Correct anwer!!') else: print('Wrong answer!! The correct answer is LOFI!!') def question2(): Q2 = input("Who is the most trustful person in the world?") Ans = ["Lofi", "Loafer", "Lofe"] if any(Q2 in item for item in Ans): print("Correct answer!! U WIN!!!!") else: print("WRONG ANSWER!!") question() question2()