Missing line of codes: Return to main menu or exit the program (Python)

Viewed 15

Feel free to remove or downvote if the question is inappropriate. Thank you!

We were given a problem and I missed some of the main components of the problem:

After input and computations always ask if user wants to input another, if not, ask to return to main menu or exit the program entirely.

At the main menu, if the user chooses to Exit, ask if he/sure to exit

To remove my confusion, what line of codes do I need to include for the program to ask if you want to return or exit the program and ask again if he/she is sure?

CHOICE = 0
HW = 0
HR = 0
GP = 0
IT = 0
RD = 0
SSS = 0
TD = 0
OT = 0

AYAW = True
while AYAW:
print("*" * 100)
print(" " * 100)
print(" " * 40 + "PAYROLL SYSTEM MENU" + " " * 35)

print(" " * 35 + "[1] Employee Data Input" + " " * 35)
print(" " * 35 + "[2] Employee Grosspay Computation" + " " * 35)
print(" " * 35 + "[3] Employee Deduction Computation" + " " * 35)
print(" " * 35 + "[4] Employee Netpay Computation" + " " * 35)
print(" " * 35 + "[5] Exit" + " " * 35)

#CHOICE
CHOICE = input(" " * 40 + "CHOICE ===> ")
print(" " * 100)
print("*" * 100)

#Employee Data Input
if (CHOICE == "1"):
    input("Employee Name (Last Name, First Name, Middle Initial: ")
    int(input("Employee Number: "))
    input("Department (Marketing/Production/Logistics/Packaging/Purchasing/Admin): ")
    input("Status (Permanent/Probationary/Contractual): ")
    HW = int(input("Employee's Rate per hour: "))
    HR = int(input("Employee's Hours Worked: "))

#Grosspay

GP = HW * HR
if (CHOICE == "2"):
    print("Grosspay:" ,GP)

#Deduction

if (CHOICE == "3"):
    IT = 0

    if (GP > 40000):
        IT = GP * 0.12

    if (GP < 1500):
        RD = GP * 0.01
    else:
        RD = GP * 0.02

        SSS = GP * 0.045

        TD = IT + RD + SSS
    print("Total Deductions", TD)

#Netpay

if (CHOICE == "4"):
    OT = 0
    if (HW > 40):
        OT = GP * 0.015 

    NP = (GP + OT) - TD 
    print("Netpay", NP)

#End the program

if (CHOICE == "5"):
    AYAW = False
    print("Done!")
1 Answers
  • Encapsulate the process in a function
  • In a loop:
    • Call the function
    • Ask the user to make a/some decision(s)
    • If user desires to quit exit the loop
Related