Commit 23cf2c63 by BellCodeEditor

auto save

parent 86467fcb
import 返回
import 返回
a=返回.diancan()
b=返回.sum()
\ No newline at end of file
def diancan(): def diancan():
def diancan(): def diancan():
total = [] total = []
while True: while True:
unit= input("请输入:") unit= input("请输入:")
if unit== 'q': if unit== 'q':
break break
else: else:
try: try: #尝试执行
unit = int(unit) unit = int(unit) #尝试执行把输入的unit转换成整数类型
except: except:
print("请重新输入一个数字") print("请重新输入一个数字") #报错的话就会有重新输入的报错提示
else: else:
total.append(unit) total.append(unit) #如果可以转换就在列表末尾添加输入的unit
return total return total #返回列表
def sum(money): def sum(money):# 计算价钱的函数 money是形参 也就是上边刚才输入的列表
count = 0 count=0 #计算累加和的变量
for i in money: for i in money: #遍历money列表
count = count + i count+=i #依次计算列表中的价格
return count return count #返回count
zhangdan=diancan() #zhangdan是我们的列表 a=diancan() #用来接收diancan()函数中的列表
zonghe=sum(zhangdan) b=sum(a) #把diancan()函数中的列表当做sum()中的实参
print(zonghe) print(b)#打印出计算的结果
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment