Commit aec14ad3 by BellCodeEditor

auto save

parent 578e41ee
Showing with 20 additions and 4 deletions
total = [] #把以下代码封装进new_input里面
while True: def new_input():
total = []
while True:
unit= input("请输入:") unit= input("请输入:")
if unit== 'q': if unit== 'q':
break break
else: else:
#尝试把输入的内容转换为整数类型
#输入的内容不是数字:使用except捕捉异常
#提示“请输入数字”
#输入的数字:添加到列表里
total.append(unit) total.append(unit)
print(total) #print(total)
\ No newline at end of file #返回值
return total
#自定义一个计算总价格的函数count
def count(money):
sum=0
for i in money:
sum+=i#加和
#返回值
abc=new_input()
cba=count(abc)
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