Commit aec14ad3 by BellCodeEditor

auto save

parent 578e41ee
Showing with 25 additions and 9 deletions
total = []
while True:
unit= input("请输入:")
if unit== 'q':
break
else:
total.append(unit)
print(total)
\ No newline at end of file
#把以下代码封装进new_input里面
def new_input():
total = []
while True:
unit= input("请输入:")
if unit== 'q':
break
else:
#尝试把输入的内容转换为整数类型
#输入的内容不是数字:使用except捕捉异常
#提示“请输入数字”
#输入的数字:添加到列表里
total.append(unit)
#print(total)
#返回值
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