Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. # Author: Lockegogo
  2.  
  3.  
  4. things = [
  5. ["pen", 30],
  6. ["macbook", 5000],
  7. ["ipad", 3000],
  8. ["iphone", 6000],
  9. ["book", 100]
  10. ]
  11.  
  12. money = input("please input your money: ")
  13. mythings = []
  14.  
  15. if money.isdigit():
  16. money = int(money)
  17. while True:
  18. for index, item in enumerate(things): #把列表的下标取出来
  19. print(index, item)
  20. #print(things.index(item), item)
  21.  
  22. user_choice = input("choose one things: ")
  23. if user_choice.isdigit():
  24. user_choice = int(user_choice)
  25. if user_choice < len(things) and user_choice > -1: #len用来取列表的动态长度
  26. p_item = things[user_choice]
  27. if p_item[1] <= money:
  28. mythings.append(p_item)
  29. money = money - p_item[1]
  30. print("Added %s into your shopping list, your current balance is \033[31;1m%s\033[0m" %(p_item, money))
  31. else:
  32. print("\033[33;1myour money is insufficient!\033[0m")
  33. continue
  34. else:
  35. print("invalid input!")
  36. continue
  37.  
  38.  
  39.  
  40. elif user_choice == "q":
  41. print("your shopping lists are:")
  42. for i in mythings:
  43. print(i)
  44. print("your current money is: ", money)
  45. exit() #退出
  46.  
  47. else:
  48. print("invalid option")
  49. continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement