Apr-30-2022, 09:27 PM
My two cents
from tabulate import tabulate from subprocess import call import platform clear = 'cls' if platform == 'win32' else 'clear' sweets = {1: ['1 Snickers Ice Cream Bar', 100], 2: ['2 Nutter Butters', 200], 3: ['3 Twix', 300], 4: ['4 Twizzlers', 400], 5: ['5 Ice Cream Sandwich', 500] } calories = 0 mychoices = [] choices = [[sweets[items][0]] for items in sweets.keys()] call(clear) while True: print(tabulate(choices, headers=['Items'])) print() print('Choose a number from the list of items or q to quit\n') choice = input('>> ') if str(choice) == 'q': break try: call(clear) choice = int(choice) if isinstance(choice, int): try: mychoices.append(sweets[int(choice)][1]) print(f'Calories Consummed: {sum(mychoices)}\n') except KeyError: call(clear) print('You can only choose from the menu.\n') except ValueError: call(clear) print('You can only enter whole numbers\n')
Output:Calories Consummed: 900
Items
------------------------
1 Snickers Ice Cream Bar
2 Nutter Butters
3 Twix
4 Twizzlers
5 Ice Cream Sandwich
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts