Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
For Loops Driving Me Insane
#8
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
Pedroski55 likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
For Loops Driving Me Insane - by Guybrush3pwood - Apr-29-2022, 07:54 PM
RE: For Loops Driving Me Insane - by deanhystad - Apr-29-2022, 10:12 PM
RE: For Loops Driving Me Insane - by Guybrush3pwood - Apr-29-2022, 11:02 PM
RE: For Loops Driving Me Insane - by deanhystad - Apr-30-2022, 03:00 AM
RE: For Loops Driving Me Insane - by Pedroski55 - Apr-30-2022, 04:59 AM
RE: For Loops Driving Me Insane - by Guybrush3pwood - Apr-30-2022, 12:26 PM
RE: For Loops Driving Me Insane - by Axel_Erfurt - Apr-30-2022, 11:35 AM
RE: For Loops Driving Me Insane - by menator01 - Apr-30-2022, 09:27 PM
RE: For Loops Driving Me Insane - by Pedroski55 - May-01-2022, 05:07 AM
RE: For Loops Driving Me Insane - by snippsat - May-01-2022, 11:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to find difference between fake driving license or real using python? pjaymn 5 2,972 Jun-14-2024, 07:01 AM
Last Post: Pedroski55
  Issue with uninstalling Python that is driving me crazy traxus 0 365 Mar-30-2024, 04:37 PM
Last Post: traxus
  Weird behavior with Led Driving code rgkaizen 0 2,817 Jul-14-2017, 04:23 AM
Last Post: rgkaizen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020