Commit 475783d0 by BellCodeEditor

auto save

parent 365efaec
try:
# 尝试执行的代码
except:
# 如果try下面的代码报错,就执行except下面的代码
else:
# 如果try下面的代码没有报错,就执行else下面的代码
# 不缩进的代码最终会被执行
def 函数名(形式参数):
函数主体
函数名(实际参数)
\ No newline at end of file
def new_input():
total = []
def new_input(): # 自定义函数用来将价格添加到列表中
total = [] # 创建空列表,用来保存菜品价格
while True:
unit= input("请输入:")
if unit== 'q':
if unit== 'q': # 如果按下“q”,跳出循环 quit
break
else:
else: # 如果没有按下“q”
try: # 尝试执行的代码
unit=int(unit)
except: # 如果try下面的代码报错,就执行except下面的代码
print("要输入整数呀")
else: # 如果try下面的代码没有报错,就执行else下面的代码
total.append(unit)
print(total)
new_input()
\ No newline at end of file
return total # 返回已经添加完菜品价格的列表
def sum(money): # 定义一个用来计算总价的函数
c=0
for i in money:
c+=i # c=c+i
return c
result=new_input() # 调用new_input()
a=sum(result) # 调用sum(money)
print(result) # 打印/输出result
print(a) # 打印总价
import func
a=func.new_input()
b=func.sum(a)
print("本次跳水比赛的总分为:",b)
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