Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Author: Lockegogo
- things = [
- ["pen", 30],
- ["macbook", 5000],
- ["ipad", 3000],
- ["iphone", 6000],
- ["book", 100]
- ]
- money = input("please input your money: ")
- mythings = []
- if money.isdigit():
- money = int(money)
- while True:
- for index, item in enumerate(things): #把列表的下标取出来
- print(index, item)
- #print(things.index(item), item)
- user_choice = input("choose one things: ")
- if user_choice.isdigit():
- user_choice = int(user_choice)
- if user_choice < len(things) and user_choice > -1: #len用来取列表的动态长度
- p_item = things[user_choice]
- if p_item[1] <= money:
- mythings.append(p_item)
- money = money - p_item[1]
- print("Added %s into your shopping list, your current balance is \033[31;1m%s\033[0m" %(p_item, money))
- else:
- print("\033[33;1myour money is insufficient!\033[0m")
- continue
- else:
- print("invalid input!")
- continue
- elif user_choice == "q":
- print("your shopping lists are:")
- for i in mythings:
- print(i)
- print("your current money is: ", money)
- exit() #退出
- else:
- print("invalid option")
- continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement