Commit 4bed2ad7 by BellCodeEditor

auto save

parent a526bd91
def charu():
total = []
while True:
unit= input("请输入:")
if unit== 'q':
break
else:
unit=int(unit)
total.append(unit)
total = []
while True:
unit= input("请输入:")
if unit== 'q':
break
else:
unit=int(unit)
total.append(unit)
return total #返回total
......
def diancan():
def diancan():
total = []
while True:
unit= input('请输入(q退出):')
if unit== 'q':
break
else:
try:
unit = int(unit)
except:
print("请重新输入一个数字")
else:
total.append(unit)
return total
def sum(b): # 计算价钱的函数 b是形参 也就是上边刚才输入的列表
w=0 #计算累加和的变量
for i in b: #遍历b列表
w+=i #依次计算列表中的价格
return w #返回w
a=diancan() #a是diancan函数中的列表
e=sum(a) #给sum函数传入实参a也就是价格列表
print(e) #输出总共的价格
import 函数返回值
import 函数返回值
a=函数返回值.diancan()
b=函数返回值.sum()
print(b)
\ 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