Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- #create shopping list with automatic calculation
- def display_help():
- print('''
- =======> Help <=======
- 'HELP' to display this menu
- 'START' to start creating your shopping list
- 'SHOW' to display your current items
- 'QUIT' to exit the program
- ''')
- #create a list with the items needed
- #
- def clear_screen():
- os.system("cls" if os.name == "nt" else "clear")
- #Create function to change values of current items or update price of items in the cart
- def shopping_list():
- clear_screen()
- print('It's time to go shopping!')
- #Convert all floating point numbers to max digits of 2 after the decimal
- clear_screen()
- item_dict = {}
- print('Enter HELP at any moment if you need help or EXIT to return to the main menu')
- cart = 0
- def show_items():
- for key, value in item_dict.items():
- print(key + '-' * 5 + str(value))
- print('Current cart total: ',sum(item_dict.values()))
- while True:
- shop = input('Please enter an item: ')
- if shop.upper() == 'HELP':
- display_help()
- continue
- elif shop.upper() == 'EXIT':
- #Show total with taxes (or without taxes) with all the items in cronological order
- #start without taxes first
- print("Goodbye")
- break
- elif shop.upper() == 'SHOW':
- show_items()
- continue
- print(f'You have added {shop} to your listn')
- try:
- cost = float(input(f'Price of {shop}: '))
- item_dict[shop] = cost
- cart = sum(item_dict.values())
- print(f'You entered {cost} as the price of {shop}n')
- print(f'You now have {len(item_dict)} items in your list.n')
- print(f'The total currently on your cart is {cart}')
- add_more_items = input('Would you like to add more items?(Y/N) ')
- if add_more_items == 'Y'.lower():
- continue
- else:
- print(f'Here's your cart and your total: n')
- raise KeyboardInterrupt('Goodbye')
- continue
- except ValueError:
- print('Please enter a number')
- def begin_attempt():
- print('Here's a list of possible commands: HELP, SHOP, EXIT')
- print('Welcome! What would you like to do?')
- while True:
- choose = input('> ')
- if choose.upper() == 'SHOP':
- print('Shopping has begunn')
- shopping_list()
- elif choose.upper() == 'HELP':
- display_help()
- continue
- elif choose.upper() == 'EXIT':
- print("Goodbye")
- break
- begin_attempt()
Add Comment
Please, Sign In to add comment