python怎么创建变量balance_在Python中将变量从一个函数修改为另一个函数

以下是有问题的功能:

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在函数外定义 . 任何帮助表示赞赏 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值