Guest User

Untitled

a guest
May 25th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. import os
  2.  
  3. #create shopping list with automatic calculation
  4.  
  5.  
  6. def display_help():
  7. print('''
  8. =======> Help <=======
  9. 'HELP' to display this menu
  10. 'START' to start creating your shopping list
  11. 'SHOW' to display your current items
  12. 'QUIT' to exit the program
  13. ''')
  14. #create a list with the items needed
  15. #
  16.  
  17. def clear_screen():
  18. os.system("cls" if os.name == "nt" else "clear")
  19.  
  20.  
  21.  
  22. #Create function to change values of current items or update price of items in the cart
  23.  
  24.  
  25.  
  26. def shopping_list():
  27. clear_screen()
  28. print('It's time to go shopping!')
  29. #Convert all floating point numbers to max digits of 2 after the decimal
  30. clear_screen()
  31. item_dict = {}
  32. print('Enter HELP at any moment if you need help or EXIT to return to the main menu')
  33. cart = 0
  34. def show_items():
  35. for key, value in item_dict.items():
  36. print(key + '-' * 5 + str(value))
  37. print('Current cart total: ',sum(item_dict.values()))
  38. while True:
  39. shop = input('Please enter an item: ')
  40. if shop.upper() == 'HELP':
  41. display_help()
  42. continue
  43. elif shop.upper() == 'EXIT':
  44. #Show total with taxes (or without taxes) with all the items in cronological order
  45. #start without taxes first
  46. print("Goodbye")
  47. break
  48. elif shop.upper() == 'SHOW':
  49. show_items()
  50. continue
  51. print(f'You have added {shop} to your listn')
  52. try:
  53. cost = float(input(f'Price of {shop}: '))
  54. item_dict[shop] = cost
  55. cart = sum(item_dict.values())
  56. print(f'You entered {cost} as the price of {shop}n')
  57. print(f'You now have {len(item_dict)} items in your list.n')
  58. print(f'The total currently on your cart is {cart}')
  59. add_more_items = input('Would you like to add more items?(Y/N) ')
  60. if add_more_items == 'Y'.lower():
  61. continue
  62. else:
  63. print(f'Here's your cart and your total: n')
  64. raise KeyboardInterrupt('Goodbye')
  65. continue
  66. except ValueError:
  67. print('Please enter a number')
  68.  
  69.  
  70.  
  71. def begin_attempt():
  72. print('Here's a list of possible commands: HELP, SHOP, EXIT')
  73. print('Welcome! What would you like to do?')
  74. while True:
  75. choose = input('> ')
  76. if choose.upper() == 'SHOP':
  77. print('Shopping has begunn')
  78. shopping_list()
  79. elif choose.upper() == 'HELP':
  80. display_help()
  81. continue
  82. elif choose.upper() == 'EXIT':
  83. print("Goodbye")
  84. break
  85.  
  86. begin_attempt()
Add Comment
Please, Sign In to add comment