【问题标题】:why the boolean variable isn't being assigned true?为什么布尔变量没有被赋值为真?
【发布时间】:2020-02-01 08:47:17
【问题描述】:

即使我输入“1234”,accountAccess 仍然是 False,所以程序不断要求输入密码。我知道可能有数百种其他方法可以做到这一点,但我对 Python 有点陌生,所以我正在探索各种可能性。对不起,如果这是一个菜鸟问题:3

password = 1234
accountAccess = False
print("___Welcome to ATM___")
while accountAccess == False:
    userInput = input("Enter password: ")
    if userInput == password:
        accountAccess = True
if accountAccess == True:
    print("Permission granted!")

【问题讨论】:

  • 您的密码是一个整数,它永远不会等于用户提供的任何字符串

标签: python python-3.x boolean


【解决方案1】:

更改如下:

password = "1234"

input 返回 string,而不是 int

【讨论】:

    猜你喜欢
    • 2016-04-02
    • 1970-01-01
    • 2016-11-10
    • 1970-01-01
    • 2022-12-09
    • 1970-01-01
    • 2019-08-26
    • 2020-07-30
    • 2018-08-06
    相关资源
    最近更新 更多