ID确认系统Def()。 f.read()有很多变量的问题

时间:2019-02-14 20:05:58

标签: python

我正在构建应用运行时的确认ID功能。 问题是,当代码运行时以及第一次代码不正确时,代码会在我第三次编写不正确的代码时看到它,并自动使用代码中的system.exit 。这是什么问题?

import sys
import math
import os
import ctypes
import getpass
banmsg = 'pzdcnu'
DuomenuBaz = 'accountfile.txt'
Ban = False


class BankAccount:
    def __init__(self):
        self._balance = 0.00

    def get_balance(self):
        return self._balance

    def increase_balance(self, amount):
        self._balance += amount

    def decrease_balance(self, amount):
        self._balance -= amount

Cash = BankAccount()

def clear(): return os.system('clear')
check = True
print("~ Welcome to Ship.EU\n To register simply create a nickname\n If you have one you'l be transfered to Login Screen.")
while check:
    Vartotojo_Vardas = input("Please enter your name\n").lower()
    Vartotojo_Pass = getpass.getpass("Please enter your password\n")
    if " " in Vartotojo_Pass or " " in Vartotojo_Vardas or len(Vartotojo_Vardas) <3 or len(Vartotojo_Pass) <3:
        print("Error!")
        continue
    else:
        Vartotojo_ID = input("~ Create Security ID Code for your account!")
        if " " in Vartotojo_ID or len(Vartotojo_ID) != 3:
            print("ID MUST BE NOT LESS THAN 3 SYMBOLL.")
            continue
        else:
            with open(DuomenuBaz,mode='r',encoding='utf-8') as f:
                if "Vardas: "+ Vartotojo_Vardas in f.read():
                    clear()
                    print("~ Username {} exists, please Log-IN".format(Vartotojo_Vardas))
                    Login1 = input("~ Please enter your password\n").lower()
                    f.close()
                    with open(DuomenuBaz, mode="r", encoding = 'utf-8') as ACCLOGIN:
                        for line in ACCLOGIN:
                            if "Vardas: "+Vartotojo_Vardas + " Password: " + Login1 in line.strip():
                                clear()
                                check = False
                                Cash.increase_balance(20)
                                print("Successfully logged in as {}".format(Vartotojo_Vardas))
                                ACCLOGIN.close()
                                break
                            else:
                                clear()
                                print("Incorrect Login!")
                                continue
                else:
                    with open(DuomenuBaz, mode = 'a', encoding = 'UTF-8') as f:
                        Ban = True
                        f.write(f"\nVardas: {Vartotojo_Vardas} Password: {Vartotojo_Pass} ID: {Vartotojo_ID} Balance EUR {Cash.get_balance()} Ban: {Ban} ")
                        print("Vardas {} Password {} ID {} Ban {} Created!".format(Vartotojo_Vardas, Vartotojo_Pass, Vartotojo_ID,Ban))
                        f.close()
                    break
if Ban:
    Unban_MSG = input("~ Your account is banned!\n May you Want to Unban? (Y,N)\n").lower()
    if "y" in Unban_MSG:
        Ban = False
        print("~ You're unbanned")
    elif "n" in Unban_MSG:  
        print("~ BAN")
        sys.exit
else:
    print("~ You're clean@!")


Acccount_Status = print("BAN - {} Balance - {}".format(Ban, Cash.get_balance()))

checkas = True
while checkas:
    Attempts = 30
    CurrentAttemp = 0
    KickForBadCode = sys.exit
    IDConfirm = input("* [3NEMATIX]: {} Please confirm Your ID CODE... ".format(Vartotojo_Vardas))
    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()
            else:
                clear()
                CurrentAttemp += 1
                if CurrentAttemp > 3:
                    print("~ You have been kicked for too many attempts!")
                    KickForBadCode
                elif CurrentAttemp is not 3:
                    print("Wrong Attempt! {}/{}".format(CurrentAttemp,Attempts))

0 个答案:

没有答案