Python Forum
How to run code again in module ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to run code again in module ?
#3
To show code a example that works fine for task like this
So it's like deanhystad code taken a little futher,
so menu function is where start and always fall back into after run a function.
Then can restart an other task or Quit out.
from rich import print

def cargo_calc():
    '''This is how to get the volumetric weight for cargo space calculation'''
    num1 = input('Enter length number: ')
    num2 = input('Enter width number: ')
    num3 = input('Enter height number: ')
    return float(num1) * float(num2) * float(num3) / 5000

def shipment_calc():
    '''Not finish yet'''
    pass

def menu_choies():
    return '''\
    (1) Cargo space calculation)
    (2) shipment space calculation)
    ([bold red]Q[/bold red]) Quit\n'''

def menu():
    while True:
        print(menu_choies())
        choice = input('Enter your choice: ').lower()
        if choice == '1':
            print(f'Volumetric weight for cargo is {cargo_calc()}\n')
        elif choice == '2':
            shipment_calc()
        elif choice == 'q':
            return
        else:
            print(f'Not a correct choice: {choice},try again\n')

if __name__ == '__main__':
    menu()
Also trown in Rich for some colors which work for on all OS/shell even cmd🧵.
[Image: wWvxiv.png]
Reply


Messages In This Thread
How to run code again in module ? - by rajamani - Nov-09-2022, 02:42 AM
RE: How to run code again in module ? - by snippsat - Nov-10-2022, 02:38 PM

Forum Jump:

User Panel Messages

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