Commit 667f2bef by BellCodeEditor

auto save

parent 8353f20c
def add(x,y):
z = x + y
#print(z)
return z #通过return把z返回给调用函数
result = add(10,20) # 调用函数并使用变量result来接收返回值
print("两数之和是:",result)
\ No newline at end of file
import func
data = func.new_input()
score = func.sum(data)
print("总得分是:",score)
\ No newline at end of file
def new_input(): # 定义函数 def new_input(): # 定义输入价格函数
total = [] total = []
while True: while True:
unit= input("请输入:") unit= input("请输入:")
...@@ -11,7 +11,20 @@ def new_input(): # 定义函数 ...@@ -11,7 +11,20 @@ def new_input(): # 定义函数
print("请输入一个整数!") print("请输入一个整数!")
else: else:
total.append(unit) total.append(unit)
print(total) #print(total)
return total
# 调用函数(运行函数) # 调用函数(运行函数)
new_input() # price = new_input()
\ No newline at end of file # print("价格列表:",price)
# 累加函数
def sum(amount):
amount_sum = 0
for i in amount:
amount_sum += i
return amount_sum
# print("总金额是:",sum(price))
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