Commit 5cd324b7 by BellCodeEditor

auto save

parent 578e41ee
import func
a = func.new_input()
b = sum(a)
print(b)
\ No newline at end of file
try:#尝试执行的语句,该语句可能会出现错误
age = int(input("今年的年龄"))
except:#当程序出现错误时
print('要输入整数啊')
else:#当程序没有出错时进入else语句
if age<18:
print("不可以喝酒哦")
print("程序结束")
\ No newline at end of file
total = [] def new_input():
while True: total = []
unit= input("请输入:") while True:
if unit== 'q': unit= input("请输入:")
break if unit== 'q':
else: break
total.append(unit) else:
print(total) #try-except-else异常捕捉结构
\ No newline at end of file try:
unit = int(unit)
except:
print("请重新输入数字,输入一个整数")
else:
total.append(unit)
return total
#return 是返回,可以将函数内部的数据返回到函数调用的地方
#返回到函数调用处没有办法直接看到结果,需要配合print函数来输出查看
def sum(money):#money 是一个参数,是形参
count = 0
for i in money:
count += i
return count
# p = new_input()
# print(p)
# a = sum(p)#p是一个列表,存储菜品单价的列表
# print(a)
\ 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