Commit caf46cda by BellCodeEditor

auto save

parent bfd9a984
import func
data = func.new_input() # 模块名称.函数名称()
result = func.amont(data)
print("总金额是:",result)
...@@ -6,8 +6,25 @@ def new_input(): ...@@ -6,8 +6,25 @@ def new_input():
if unit== 'q': if unit== 'q':
break break
else: else:
total.append(unit) try:
unit = int(unit)
except:
print("请输入整数!")
else:
total.append(int(unit))
print(total) print(total)
return total # return 返回total给调用
# 调用函数 # 调用函数
new_input() price_list = new_input() # price_list 是接收函数返回值
def amont(money): # 形式参数只是在定义函数时写上
sm = 0
for i in money:
sm += i
return sm
result = amont(price_list) # 调整用函数时,要根据"形式参数"个数来赋值"实际参数"
print("总金额是:",result)
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