Commit 52cc1ff9 by BellCodeEditor

auto save

parent 209ee192
Showing with 17 additions and 10 deletions
try: import func
print(3/1)
except: d = func.price()
print('不行') print(d)
print(2/0)
\ No newline at end of file
total = []
def price(): def price():
total = []
while True: while True:
unit= input("请输入:") unit= input("请输入:")
if unit== 'q': if unit== 'q':
break break
else: else:
total.append(unit) try:
print(total) unit=int(unit) #尝试将输入的内容转换成整数
\ No newline at end of file except:
print('请输入正确的内容') #不能转换执行这一行
else:
total.append(unit) #能转换执行这一行
return total
print(sum(price())) #sum(),Python自带的求和函数,可以求一个序列中所有数字的和
\ 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