[英](Python) if statement not executing
while has_answered == False:
new_choice = input("Are you a new user, (Y) or (N) to choose (X) to end the script and see the class scores")
if new_choice == "Y":
new_user = True
end_script = False
has_answered = True
if new_choice == "X":
end_script = True
new_user = False
has_answered = True
else:
new_user = False
end_script = False
if end_script == False:
print(">>>>>>>>>>>>>>>>>>>>>>>>>")
if new_user == True:
player_class = input("Please enter what class you are in (A),(B) or (C)")
player_name = input("Please enter your name: ")
questions = 0
score = 0
print("You will be tested on your arithmetic abilities with this quiz")
start_choice = input("Would you like to start the game? (Y)or(N)")
So what would happen is if you entered "Y" it would execute print(">>>>>>>>>>>>>>>>>>>>>>>>>") but skip the whole main part of the code after the "if new_user == True:"所以会发生什么如果你输入“Y”它会执行 print(">>>>>>>>>>>>>>>>>>>>>>>>>") 但跳过整个主要部分“if new_user == True:”之后的代码
I'm not sure what I am doing wrong as I'm setting all of the parameters correctly for the if statement to be executed我不确定我做错了什么,因为我为要执行的 if 语句正确设置了所有参数
Changing your first if statement as If else ladder will set "Y" choice values properly.将您的第一个 if 语句更改为 If else 阶梯将正确设置“Y”选择值。
if new_choice == "Y":
new_user = True
end_script = False
has_answered = True
elif new_choice == "X":
end_script = True
new_user = False
has_answered = True
else:
new_user = False
end_script = False
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.