为了账号安全,请及时绑定邮箱和手机立即绑定

bool 和 if 语句的问题

bool 和 if 语句的问题

忽然笑 2021-11-09 19:50:23
我正在构建一个 ID Confirm 系统,用户有 3 次尝试输入 ID 正确,如果没有,系统将退出。我的问题是当用户最后一次输入正确的 ID 时,当代码正确时,语句写出 ID 是正确的,第二行显示他,他输入了太多的尝试和系统正在退出。我该如何修复这个错误?我该如何解决,当用户在 3/3 次尝试中输入正确的 ID 时,系统会说,正确,我们可以破坏 if 语句。我的代码:checkas = TrueAttempts = 3CurrentAttemp = 0KickForBadCode = sys.exitwhile checkas:    CurrentAttemp += 1    IDConfirm = input("* [3NEMATIX]: {} Please confirm Your ID CODE... Attempt! {}/{} ".format(Vartotojo_Vardas, CurrentAttemp, Attempts))    with open (DuomenuBaz, mode = 'r', encoding = 'utf-8') as Confirm:        for line in Confirm:            if "Vardas: "+Vartotojo_Vardas + " Password: " + Vartotojo_Pass + " ID: " + IDConfirm in line.strip():                print("Correct!")                Confirm.close()                checkas = False                break            elif "Vardas: "+Vartotojo_Vardas + " Password: " + Vartotojo_Pass + " ID: " + IDConfirm in line.strip() and CurrentAttemp > 2:                clear()                print("Correct!")                Confirm.close()                checkas = False                break            elif CurrentAttemp >2:                clear()                print("~ You have been kicked for too many attempts!")                checkas = False                sys.exit
查看完整描述

2 回答

?
月关宝盒

TA贡献1772条经验 获得超5个赞

您exit只需要在CurrentAttempis >than时才需要Attempts。而如果Vartotojo_Pass是在正确的<=到Attempts。


尝试更换这部分:


if "Vardas: "+Vartotojo_Vardas + " Password: " + Vartotojo_Pass + " ID: " + IDConfirm in line.strip():

                print("Correct!")

                Confirm.close()

                checkas = False

                break

            elif "Vardas: "+Vartotojo_Vardas + " Password: " + Vartotojo_Pass + " ID: " + IDConfirm in line.strip() and CurrentAttemp > 2:

                clear()

                print("Correct!")

                Confirm.close()

                checkas = False

                break

            elif CurrentAttemp >2:

                clear()

                print("~ You have been kicked for too many attempts!")

                checkas = False

                sys.exit

有了这个:


        if "Vardas: "+Vartotojo_Vardas + " Password: " + Vartotojo_Pass + " ID: " + IDConfirm in line.strip():

            print("Correct!")

            Confirm.close()

            checkas = False

            break

        elif "Vardas: "+Vartotojo_Vardas + " Password: " + Vartotojo_Pass + " ID: " + IDConfirm in line.strip() and CurrentAttemp < Attempts:

            clear()

            print("Correct!")

            Confirm.close()

            checkas = False

            break

        elif CurrentAttemp > Attempts:

            clear()

            print("~ You have been kicked for too many attempts!")

            checkas = False

            sys.exit


查看完整回答
反对 回复 2021-11-09
?
慕尼黑5688855

TA贡献1848条经验 获得超2个赞

我修复了它,它有太多的 if 语句,导致脚本每次都重新布尔值,并且脚本无法运行。问题只是 if 语句。


 checkas = True

    Attempts = 3

    CurrentAttemp = 0

    KickForBadCode = sys.exit

    while checkas:

        CurrentAttemp += 1

        if CurrentAttemp > 3:

            checkas = False

            clear()

            print("~ You have been kicked for too many attempts!")

            sys.exit

        else:

            IDConfirm = input("* [3NEMATIX]: {} Please confirm Your ID CODE... Attempt! {}/{} ".format(Vartotojo_Vardas, CurrentAttemp, Attempts))

            with open (DuomenuBaz, mode = 'r', encoding = 'utf-8') as Confirm:

                for line in Confirm:

                    if "Vardas: "+Vartotojo_Vardas + " Password: " + Vartotojo_Pass + " ID: " + IDConfirm in line.strip():

                        print("Correct!")

                        Confirm.close()

                        checkas = False

                        break

                    else:

                        checkas = True

                        clear()


查看完整回答
反对 回复 2021-11-09
  • 2 回答
  • 0 关注
  • 158 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信