【问题标题】:Im new to programming and im trying to run this code on python but ive done something wrong can someone fix my code i cant seem to get it right我是编程新手,我试图在 python 上运行这段代码,但我做错了,有人可以修复我的代码,我似乎无法正确
【发布时间】:2022-01-02 03:03:19
【问题描述】:
count=0
while count < 3:
Username = input('Username: ')
Password = input('Password: ')
numAttempts = 3
     if Password=='123' and Username=='admin':
         print('Successfully logged in')
     elif:
         print('Invalid username and password!')
         count += 1
     else numAttempts > 3:
         print("Account has been blocked")

文件“”,第 8 行 如果密码=='123' 和用户名=='admin': ^ IndentationError: 意外缩进

【问题讨论】:

    标签: if-statement while-loop


    【解决方案1】:

    在 python 中,缩进很重要。您需要在

    之后标记所有内容
    while count < 3:
    

    任何条件或循环语句都需要缩进。选项卡保持一致也很重要(IE,使用制表键或相同数量的空格)。

    您的 else 和 elif 语句看起来也颠倒了您的逻辑。

    另外,您的 numAttempts 可能应该从 0 开始,并且您需要在 else 子句中更新它。 这应该可以帮助您入门。

    count=0
    while count < 3:
        Username = input('Username: ')
        Password = input('Password: ')
        numAttempts = 3
        if Password=='123' and Username=='admin':
            print('Successfully logged in')
        elif numAttempts > 3:
            print("Account has been blocked")
        else:
            print('Invalid username and password!')
            count += 1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-16
      • 1970-01-01
      • 1970-01-01
      • 2018-05-05
      • 2021-12-05
      • 2020-09-21
      • 1970-01-01
      相关资源
      最近更新 更多