Commit d99f11ef by BellCodeEditor

save project

parent 20cd336f
Showing with 16 additions and 11 deletions
def new_input(): def new_input(): #定义函数new_input()
total = [] total = [] #新建列表total
while True: while True: #无限循环
unit= input("请输入:") price= input("请输入价格") #输入的整数赋值给price变量
if unit== 'q': try: #尝试下面的语句、捕捉异常
break p=int(price) #将price转换为整数类型,赋值给p
else: except: #如果tey的语句出错,就执行下面的语句
total.append(unit) print("请输入一个整数") #输出提示文字
print(total) else: #如果没有出错,就执行下面的语句
new_input() total.append(p) #在total列表后面追加元素p
\ No newline at end of file if price== 'q': #如果price变量的值等于'q',就执行下面的语句
break #终止循环
print(total) #输出total列表的全部元素
print('_'*30) #输出30个下划线'_'
new_input() #调用函数new_input
\ 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