gpt4 book ai didi

python - 在 python 中,我在 else : yet it does not seem to actually print it after running the code 之后有一个 print 语句

转载 作者:行者123 更新时间:2023-12-01 02:50:53 25 4
gpt4 key购买 nike

pin1 = int(input("Please set a pin: "))
print("Welcome to Satan's Soul Bank, Enter ya pin!")
attempt = int(input("Please enter your pin number first"))

if attempt == pin1:
print("Select operation.")
print("1.Deposit Souls")
print("2.Withdraw Souls")
print("3.Check Soul balance")
choice = int(input("Enter choice(1/2/3):"))
elif attempt != pin1:
for i in range(2):
attempt = int(input("Invalid Attempt Please enter your pin
number again"))
else:
print ("Card Swallowed Contact SATAN")

代码本身与 else 之后的 print 语句分开工作:它似乎无法识别它并且只是错过了它,基本上我需要它来打印卡在 3 次后已被吞下,但是当我将其放入 elif 中时每次我输入密码错误时,它都会打印它,所以有没有其他方法可以解决这个问题,导致它在第三次之后打印出卡已被吞下

最佳答案

正如其他答案中提到的,elif block 涵盖了 if block 不满足的条件。为了确保在 else block 中打印语句,您可以使用 flag 变量,该变量将在最大错误之前设置为 false尝试。达到最大尝试次数后,将标志设置为true

如果flag设置为trueprint'卡片被吞下。联系撒旦...'

关于python - 在 python 中,我在 else : yet it does not seem to actually print it after running the code 之后有一个 print 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44799529/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com