Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Diner Organizer
#1
I've did this for fun and I implemented things I recently learned and want to know on things I could of possibly done differently such as made it more efficient, neatness or things that you may have liked, thanks!

# 5/20/2020

import time

# Tables

Table_A = 0
Table_B = 0
Table_C = 0

# Seats remaining

seat_A = 4
seat_B = 6
seat_C = 2

def stop():
    while True:
        for i in range(1):
            break

def intro():
  print("Welcome to Kevin's Diner Organizer!")
  time.sleep(.1)
  print("___ ___ _  _ ___ ___ ")
  time.sleep(.1)
  print("|   \_ _| \| | __| _ /")
  time.sleep(.1)
  print("| |) | || .` | _||   /")
  time.sleep(.1)
  print("|___/___|_|\_|___|_|_/")
  time.sleep(.1)
  print("Coded by NectDzN")
  time.sleep(.5)

def menu_Intro():
  time.sleep(.1)
  print("  __  __ ______ _   _ _    _ ")
  print(" |  \/  |  ____| \ | | |  | |")
  time.sleep(.1)
  print(" | \  / | |__  |  \| | |  | |")
  print(" | |\/| |  __| | . ` | |  | |")
  time.sleep(.1)
  print(" | |  | | |____| |\  | |__| |")
  print(" |_|  |_|______|_| \_|\____/\n")
  time.sleep(.5)

def menu():
    while True:
        menu_Intro()
        time.sleep(1)
        user_In = input("'S' To sit a party\n'D' Dismiss a party\n'V' view avaliable seats\n'Q' Quit the program\n----------------------\nEnter here: ")
        user_In = user_In.upper()
        if user_In == "S":
            sit()
        elif user_In == "V":
            view()
            menu()
        elif user_In == "D":
            dismiss()
        elif user_In == "Q":
            print("\nEnding program good bye...")
            stop()

# Table being shown

def view():
    time.sleep(1)
        # Showing Tabls
    print("\nShowing Tables\n")
    time.sleep(1)
        # Table A
    print("Table - A has -", (Table_A), "- people / -", (seat_A), "- seats remaining")
        # Table B
    print("Table - B has -", (Table_B), "- people / -", (seat_B), "- seats remaining")
        # Table C
    print("Table - C has -", (Table_C), "- people / -", (seat_C), "- seats remaining\n")
    time.sleep(1)

# Add Function

def add(user_In,user_Num,Table,Seat):
        # Global
    global Table_A,Table_B,Table_C,seat_A,seat_B,seat_C
        # user_Num input is added to their appropriate tables.
    for i in range(user_Num):
        Table += 1
        Seat -= 1
        # Table A
    if user_In == "A":
        # Final Results are added
        Table_A = Table
        seat_A = Seat
        # Check Function is called for limit
        check(user_In,user_Num,Table,Seat)
    elif user_In == "B":
        # Final Results are added
        Table_B = Table
        seat_B = Seat
        # Check Function is called for limit
        check(user_In,user_Num,Table,Seat)
    elif user_In == "C":
        # Final Results are added
        Table_C = Table
        seat_C = Seat
        # Check Function is called for limit
        check(user_In,user_Num,Table,Seat)

# Commands

def sit():
    global Table_A,Table_B,Table_C,seat_A,seat_B,seat_C
    while True:
            # Seat = False (Used later)
        user_Seat = False
            # Tables are shown
        view()
            # User Input
        user_In = input ("Which table would you like to choose: ")
        user_In = user_In.upper()
            # If and Elif statement based on the letter that has been choosen A/B/C
        if user_In == "A":
                # Variables for the add function
            Table = Table_A
            Seat = seat_A
            time.sleep(1)
            while user_Seat != True:
                try:
                    # People Sitting
                    user_Num = int(input("How many people are sitting? Max " + str(Seat) + ": "))
                    user_Seat = True
                except ValueError:
                    time.sleep(.5)
                    print("\nThat was not a number, try again...\n")
                    time.sleep(1)
                # Add function is called
            add(user_In,user_Num,Table,Seat)
                # The results of the Add function
            time.sleep(.5)
            print("\nTable A has", Table_A, "people in it /", seat_A, "seats remaining!\n")
            time.sleep(1)
            menu()
        elif user_In == "B":
                # Variables for the add function
            Table = Table_B
            Seat = seat_B
            time.sleep(1)
            while user_Seat != True:
                try:
                    # People Sitting
                    user_Num = int(input("How many people are sitting? Max " + str(Seat) + ": "))
                    user_Seat = True
                except ValueError:
                    time.sleep(.5)
                    print("\nThat was not a number, try again...\n")
                    time.sleep(1)
                # Add function is called
            add(user_In,user_Num,Table,Seat)
                # The results of the Add function
            time.sleep(.5)
            print("\nTable B has", Table_B, "people in it /", seat_B, "seats remaining!\n")
            time.sleep(1)
            menu()
        elif user_In == "C":
                # Variables for the add function
            Table = Table_C
            Seat = seat_C
            time.sleep(1)
            while user_Seat != True:
                try:
                    # People Sitting
                    user_Num = int(input("How many people are sitting? Max " + str(Seat) + ": "))
                    user_Seat = True
                except ValueError:
                    time.sleep(.5)
                    print("\nThat was not a number, try again...\n")
                    time.sleep(1)
                # Add function is called
            add(user_In,user_Num,Table,Seat)
                # The results of the Add function
            time.sleep(.5)
            print("\nTable C has", Table_C, "people in it /", seat_C, "seats remaining!\n")
            time.sleep(1)
            menu()

def substract(user_In,user_Num,Table,Seat):
        # Global
    global Table_A,Table_B,Table_C,seat_A,seat_B,seat_C
        # user_Num input is added to their appropriate tables.
    for i in range(user_Num):
        Table -= 1
        Seat += 1
        # Table A
    if user_In == "A":
        # Final Results are added
        Table_A = Table
        seat_A = Seat
        # Check Function is called for limit
        check(user_In,user_Num,Table,Seat)
    elif user_In == "B":
        # Final Results are added
        Table_B = Table
        seat_B = Seat
        # Check Function is called for limit
        check(user_In,user_Num,Table,Seat)
    elif user_In == "C":
        # Final Results are added
        Table_C = Table
        seat_C = Seat
        # Check Function is called for limit
        check(user_In,user_Num,Table,Seat)

def dismiss():
    global Table_A,Table_B,Table_C,seat_A,seat_B,seat_C
    while True:
            # Seat = False (Used later)
        user_Seat = False
            # Tables are shown
        view()
            # User Input
        user_In = input ("Which table would you like to choose: ")
        user_In = user_In.upper()
            # If and Elif statement based on the letter that has been choosen A/B/C
        if user_In == "A":
                # Variables for the add function
            Table = Table_A
            Seat = seat_A
            time.sleep(1)
            while user_Seat != True:
                try:
                    # People Sitting
                    user_Num = int(input("How many people are being dismissed? Max " + str(Table_A) + ": "))
                    user_Seat = True
                except ValueError:
                    time.sleep(.5)
                    print("\nThat was not a number, try again...\n")
                    time.sleep(1)
                # Add function is called
            substract(user_In,user_Num,Table,Seat)
                # The results of the Add function
            time.sleep(.5)
            print("\nTable A has", Table_A, "people in it /", seat_A, "seats remaining!\n")
            time.sleep(1)
            menu()
        elif user_In == "B":
                # Variables for the add function
            Table = Table_B
            Seat = seat_B
            time.sleep(1)
            while user_Seat != True:
                try:
                    # People Sitting
                    user_Num = int(input("How many people are being dismissed? Max " + str(Table_B) + ": "))
                    user_Seat = True
                except ValueError:
                    time.sleep(.5)
                    print("\nThat was not a number, try again...\n")
                    time.sleep(1)
                # Add function is called
            substract(user_In,user_Num,Table,Seat)
                # The results of the Add function
            time.sleep(.5)
            print("\nTable B has", Table_B, "people in it /", seat_B, "seats remaining!\n")
            time.sleep(1)
            menu()
        elif user_In == "C":
                # Variables for the add function
            Table = Table_C
            Seat = seat_C
            time.sleep(1)
            while user_Seat != True:
                try:
                    # People Sitting
                    user_Num = int(input("How many people are being dismissed? Max " + str(Table_C) + ": "))
                    user_Seat = True
                except ValueError:
                    time.sleep(.5)
                    print("\nThat was not a number, try again...\n")
                    time.sleep(1)
                # Add function is called
            substract(user_In,user_Num,Table,Seat)
                # The results of the Add function
            time.sleep(.5)
            print("\nTable C has", Table_C, "people in it /", seat_C, "seats remaining!\n")
            time.sleep(1)
            menu()

def check(user_In,user_Num,Table,Seat):
    global Table_A,Table_B,Table_C,seat_A,seat_B,seat_C
    # Check is set to false
    check = False
    # Check While Loop until = True
    while check != True:
        if Table_A > 4:
            # Warning Message
            time.sleep(.5)
            print("\nLimit has been reached! Pick another table or number\n")
            time.sleep(.5)
            # Subtraction of user_Num input
            for i in range(user_Num):
                Table -= 1
                Seat += 1
            Table_A = Table
            seat_A = Seat
            check = True
        elif Table_B > 6:
            # Warning Message
            time.sleep(.5)
            print("\nLimit has been reached! Pick another table or number\n")
            time.sleep(.5)
            # Subtraction of user_Num input
            for i in range(user_Num):
                Table -= 1
                Seat += 1
            Table_B = Table
            seat_B = Seat
            check = True
        elif Table_C > 2:
            # Warning Message
            time.sleep(.5)
            print("\nLimit has been reached! Pick another table or number\n")
            time.sleep(.5)
            # Subtraction of user_Num input
            for i in range(user_Num):
                Table -= 1
                Seat += 1
            Table_C = Table
            seat_C = Seat
            check = True
            # Subtraction -------------------------------------------------------
        if Table_A < 0:
            # Warning Message
            time.sleep(.5)
            print("\nLimit has been reached! Reversing input...\n")
            time.sleep(.5)
            # Subtraction of user_Num input
            for i in range(user_Num):
                Table += 1
                Seat -= 1
            Table_A = Table
            seat_A = Seat
            check = True
        elif Table_B < 0:
            # Warning Message
            time.sleep(.5)
            print("\nLimit has been reached! Reversing input...\n")
            time.sleep(.5)
            # Subtraction of user_Num input
            for i in range(user_Num):
                Table += 1
                Seat -= 1
            Table_B = Table
            seat_B = Seat
            check = True
        elif Table_C < 0:
            # Warning Message
            time.sleep(.5)
            print("\nLimit has been reached! Reversing input...\n")
            time.sleep(.5)
            # Subtraction of user_Num input
            for i in range(user_Num):
                Table += 1
                Seat -= 1
            Table_C = Table
            seat_C = Seat
            check = True
            # Subtraction
        else :
            check = True

def main():
    while True:
        time.sleep(1)
        # Intro Called
        intro()
        # Start Input
        start = input("\nType 'Start' to begin: ")
        start = start.upper()
        # Start If statements
        if start == 'START':
            menu()
        elif start == "" :
            counter = 3
            time.sleep(1)
            # 3 2 1 Counter
            print("\nI did not get any input restarting in...\n")
            for i in range (3):
                time.sleep(1)
                print(counter,"\n")
                counter -= 1
        else:
            counter = 3
            time.sleep(1)
            print("\nI did not understand restarting in...\n")
            # 3 2 1 counter
            for i in range (3):
                time.sleep(1)
                print(counter,"\n")
                counter -= 1

main()
Reply
#2
range can be made to count backwards so instead of
counter = 3
# 3 2 1 Counter
print("\nI did not get any input restarting in...\n")
for i in range (3):
    print(counter,"\n")
    counter -= 1
you can use
print("\nI did not get any input restarting in...\n")
for counter in range(3,0,-1):
    print(f'{counter}\n')
see https://docs.python.org/3/library/stdtyp...ange#range
Reply
#3
(May-31-2020, 08:53 PM)Yoriz Wrote: range can be made to count backwards
I did not know that, thank you for telling me!
Reply


Forum Jump:

User Panel Messages

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