gpt4 book ai didi

python - ATM 机编程

转载 作者:太空宇宙 更新时间:2023-11-03 21:42:13 26 4
gpt4 key购买 nike

我的任务是创建一个 ATM 类型的程序。下面是我的主要功能(不包括存款、取款和查询余额功能)。当我运行此代码时,程序会重复循环 pin 函数,即使我输入 0 或 1234 也是如此。它会重复指示用户输入 pin 码。我认为我的所有缩进都是正确的,但我想我在代码中的某个地方搞砸了。

def main():
pin_number = input("Please enter your pin number")
stop = False

while not is_authorized(pin_number) and stop!= True:

if pin_number == "0":
stop == True
if pin_number == "1234":
stop == False

if stop != True:
while True:
choice = display_menu()
if choice == 1:
deposit()
elif choice == 2:
withdraw()
elif choice == 3:
check_balance()

最佳答案

在 if 语句中,您应该使用 = 而不是 ==。第一个用于为变量赋值,就像您尝试做的那样。第二个用于比较两个值是否相等并返回 bool 值(true/false)。

关于python - ATM 机编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52769765/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com