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区,它只是打印它,每次我得到的引脚错误,所以有没有其他方法来绕过,导致打印卡已吞咽后3次
如其他答案所述,
elif
块覆盖了if
块未满足的条件。为了确保在else
块中打印语句,可以使用flag
变量,该变量将在最大错误尝试之前设置为false
。达到最大尝试次数后,将flag
设置为true
。你知道吗如果
flag
设置为true
,则print
卡被吞下。联系撒旦…'你需要重组你的代码来得到你想要的。你知道吗
我们循环3次,如果用户得到正确的pin码就退出,只有在pin码正确的情况下才提供进一步的选项。你知道吗
在你的代码里
由于其中一个条件始终保持不变(无论
attempt
是否等于pin1
),程序将永远不会到达else
部分。你知道吗相关问题 更多 >
编程相关推荐