Commit e9f63d83 by BellCodeEditor

auto save

parent 23cf2c63
def diancan(): def diancan():
def diancan(): def diancan():
total = [] total = []
while True: while True:
unit= input('请输入(q退出):') unit= input("请输入:")
if unit== 'q': if unit== 'q':
break break
else: else:
try: try:
unit = int(unit) unit=int(unit)
except: except:
print("请重新输入一个数字") print("输入的不是价格")
else: else:
total.append(unit) total.append(unit)
return total return total
def sum(b): # 计算价钱的函数 b是形参 也就是上边刚才输入的列表 def sum(money):
w=0 #计算累加和的变量 count = 0
for i in b: #遍历b列表 for i in money:
w+=i #依次计算列表中的价格 count = count + i
return w #返回w return count
a=diancan() #a是diancan函数中的列表 a=diancan()
e=sum(a) #给sum函数传入实参a也就是价格列表 b=sum(a)
print(e) #输出总共的价格 print(b)
\ No newline at end of file
import 返回 import time
import 返回 import time
a=返回.diancan() i=0
b=返回.sum() while True:
\ No newline at end of file i+=1
print(i)
time.sleep(1)
import 返回 import 函数返回值 #只能导入以中英文命名的文件
import 返回 import 函数返回值 #只能导入以中英文命名的文件
a=返回.diancan() a=函数返回值.diancan()
b=返回.sum() b=函数返回值.sum()
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