标签:NPU append opp current art mac rate 打印 hone
2020-02-17
_author_ = "chen"
product_list = [
(‘iphone‘, 5800),
(‘mac book‘, 9800),
(‘bike‘, 800),
(‘watch‘, 10600),
(‘coffee‘, 31),
(‘python‘, 120),
]
shopping_list = []
salary = input("input your salary:")
if salary.isdigit():
salary = int(salary)
while True:
for index, item in enumerate(product_list): # enumerate取下标
print(index, item)
user_choice = input("选择要买什么?:")
if user_choice.isdigit(): # 判别是不是数字
user_choice = int(user_choice)
if user_choice < len(product_list) and user_choice >= 0:
p_item = product_list[user_choice]
if p_item[1] <= salary: # 买得起
shopping_list.append(p_item)
salary -= p_item[1]
print("Added %s into shopping cart ,your current balance is\033[31:1m %s\033[0m" % (
p_item, salary)) # 打印颜色
else:
print(":\033[41;1m你的余额只剩[%s]啦,买毛线啊\033[0m" % salary)
else:
print("product code [%s] is not exist!" % user_choice)
elif user_choice == ‘q‘:
print("------shopping list------")
for p in shopping_list:
print(p)
print("your current balance", salary)
break
else:
print("invalid option")
标签:NPU append opp current art mac rate 打印 hone
原文地址:https://www.cnblogs.com/cy2268540857/p/12322690.html