以下是有问题的功能:
def ATM():
global mode
pinNum = input('Please enter your 4 digit secret code: ')
userBalance = float(dict2[pinNum])
while mode == 0:
if pinNum in dict1:
greet = input('Hello {}, please enter 1 to check your balance, 2 to make a withdrawal, 3 to make a deposit, or 4 to end your session: '.format(dict1[pinNum]))
if greet == '1':
balance(userBalance)
elif greet == '2':
withdraw(userBalance)
elif greet == '3':
deposit(userBalance)
elif greet == '4':
mode = 1
def balance(userBalance):
print('Your current balance is {}.'.format(userBalance))
def deposit(userBalance):
amount = input('Please enter the amount you wish to be deposited: ')
userBalance += float(amount)
return userBalance
def withdraw(userBalance):
amount = input('Please enter the amount you wish to withdraw" ')
if userBalance - float(amount) < 0:
print('You do not have sufficient funds.')
else:
userBalance -= float(amount)
当我在ATM()中调用存款或取款功能时,我无法调整余额 . 我想我可能无法在存款和取款功能中正确返回数据 . 该程序模拟ATM供参考,dict1和dict2在函数外定义 . 任何帮助表示赞赏 .