Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 银行ATM程序登录_Python - Fatal编程技术网

Python 银行ATM程序登录

Python 银行ATM程序登录,python,Python,我想让这个程序作为一个银行,我如何确保正确的身份证号码必须输入正确的pin码,并根据您输入的身份证打印hello,然后打印他们的姓名,并提示他们在银行有多少钱 attempts = 0 store_id = [1057, 2736, 4659, 5691, 1234, 4321] store_name = ["Jeremy Clarkson", "Suzanne Perry", "Vicki Butler-Henderson", "Jason Plato"] store_balance = [1

我想让这个程序作为一个银行,我如何确保正确的身份证号码必须输入正确的pin码,并根据您输入的身份证打印hello,然后打印他们的姓名,并提示他们在银行有多少钱

attempts = 0
store_id = [1057, 2736, 4659, 5691, 1234, 4321]
store_name = ["Jeremy Clarkson", "Suzanne Perry", "Vicki Butler-Henderson", "Jason Plato"]
store_balance = [172.16, 15.62, 23.91,  62.17, 131.90, 231.58]
store_pin = [1057, 2736, 4659, 5691]

start = int(input("Are you a member of the Northern Frock Bank?\n1. Yes\n2. No\n"))
if start == 1:
    idguess = ""
    pinguess = ""
    while (idguess not in store_id) or (pinguess not in store_pin):
        idguess = int(input("ID Number: "))
        pinguess = int(input("PIN Number: "))
        if (idguess not in store_id) or (pinguess not in store_pin):
            print("Invalid Login")
           attempts = attempts + 1
        if attempts == 3:
            print("This ATM has been blocked for too many failed attempts.")
            break

elif start == 2:
    name = str(input("What is your full name?: "))
    pin = str(input("Please choose a 4 digit pin number for your bank account: "))
    digits = len(pin)
    balance = 100

while digits != 4:
    print("That Pin is Invalid")
    pin = str(input("Please choose a 4 digit pin number for your bank account: "))
    digits = len(pin)

store_name.append(name)
store_pin.append(pin)

你对你的计划的详细阐述给我留下了深刻的印象。以下是我对您的解决方案的看法


因此,为了创建登录模拟,我将使用字典。这样,您可以为PIN分配ID。例如:

credentials = {
    "403703": "121",
    "3900": "333",
    "39022": "900"
}
您的ID位于冒号的左侧,PIN位于右侧。您还必须使用字典将ID分配给属于该ID的名称,您猜对了

bankIDs = {
    "403703": "Anna",
    "3900": "Jacob",
    "39022": "Kendrick"
}
现在已经完成了,您可以使用if/else控制流创建虚拟登录系统。我的代码是这样编写的:

attempts = 0
try:
    while attempts < 3:
        id_num = raw_input("Enter your ID: ")
        PIN = raw_input("Password: ")
        if (id_num in credentials) and (PIN == credentials[id_num]):
            print "login success."
            login(id_num)
        else:
            print "Login fail. try again."
            attempts += 1
    if attempts == 3:
        print "You have reached the maximum amount of tries."
except KeyboardInterrupt:
    print "Now closing. Goodbye!"
字符串格式的简单使用。就在这里。显示此人的平衡也可以做到这一点。只需为它制作字典,然后在登录定义中打印代码。 代码的其余部分仍然很好。只需确保在代码底部的elif中正确缩进了while循环,以及最后两行。
希望我能帮忙。干杯

太好了!您是否有特定的问题?您需要链接id name balance pin,因此最好创建一个类并将其实例存储在列表中。好的,我了解您所做的操作,但是如果用户正在创建银行帐户,那么如何将内容添加到字典中?例如:凭据[“insertnumberhere”]=“insertothernumber”我还忘了提到我的代码是为Python2编写的,因此如果您使用Python3,唯一需要更改的是登录名,
print“Hello,{}!”.format(bankIDs[loginid])
我也使用Python2
def login(loginid):
    print "Hello, %s!" % bankIDs[loginid]