Ex-shopping car

TingKi發表於2024-03-26

-- coding:utf-8 --

Author:Tinky

salary = input("請輸入你的工資:")
pro_list = [("0.房車",100), ("1.車子", 200), ("2.電動車", 300), ("3.腳踏車", 400), ("4.滑板車", 500)]
shopping_list = []

if salary.isdigit():
salary = int(salary)
while True:
for index, item in enumerate(pro_list):
print(index, item)
user_choice = input("請選擇商品編號:")
if user_choice.isdigit():
user_choice = int(user_choice)
if len(pro_list) > user_choice >= 0:
p_item = pro_list[user_choice]
if p_item[1] <= salary:
shopping_list.append(p_item)
print("Added %s into shoppint car,your current balance is %s" % (shopping_list, salary - p_item[1]))
else:
print("\033[41:1m你的餘額為[%s]啦\033[31:0m" % (salary - p_item[1]))
else:
print("\033[40:1m商品%S不存在\033[32:0m" % pro_list[user_choice])
elif user_choice == "q":
exit("退出程式")
else:
print("invalid option")