Commit db219a8f by BellCodeEditor

auto save

parent e9f63d83
def charu(): def charu():
total = [] total = []
while True: while True:
unit= input("请输入:") unit= input("请输入:")
if unit== 'q': if unit== 'q':
break break
else: else:
unit=int(unit) unit=int(unit)
total.append(unit) total.append(unit)
print(total) print(total)
return total #返回total return total #返回total
......
def diancan(): def diancan(): #创建函数
def diancan(): def diancan(): #创建函数
total = [] total = []
while True: while True:
unit= input("请输入:") unit= input("请输入:")
...@@ -6,18 +6,18 @@ def diancan(): ...@@ -6,18 +6,18 @@ def diancan():
if unit== 'q': if unit== 'q':
break break
else: else:
try: try: #尝试执行
unit=int(unit) unit = int(unit) #尝试执行把输入的unit转换成整数类型
except: except:
print("输入的不是价格") print("请重新输入一个数字") #报错的话就会有重新输入的报错提示
else: else:
total.append(unit) total.append(unit) #如果可以转换就在列表末尾添加输入的unit
return total return total
def sum(money): def sum(money):
count = 0 count = 0
for i in money: for i in money:
count = count + i count = count + i
return count return count
a=diancan() a=diancan()#使用函数
b=sum(a) b=sum(a)
print(b) print(b)
\ No newline at end of file
import 函数返回值
import 函数返回值
a=函数返回值.diancan()
b=函数返回值.sum()
\ No newline at end of file
++ "b/\350\257\273\345\206\231.py"
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