In [ ]:
from IPython.display import clear_output
from time import asctime
##########################################################################
#Variable declaration
def calculatePay ():
    clear_output()
    print("I will print your invoice for you.")
    firstName = input("Enter a first name here ====>")
    lastName = input("Enter a last name here ====>")
    payRate = float(input("How much do you make an hour?"))
    hours = float(input("How long did you work for?"))
    averageInsur = 119.00
##########################################################################
# Overtime calculator
    if hours > 40:
        overHours = hours - 40
        overTime = (payRate * 1.5) * overHours # Amount made with overtime
        basePay = payRate * 40
        grossOver = basePay + overTime
        ssTax = grossOver * 0.153
        fedTax = grossOver * 0.101
        stateTax = grossOver * 0.0447
        totalDeduct = ssTax + fedTax + stateTax + averageInsur
        netPay = grossOver - ssTax - fedTax - stateTax - averageInsur
##########################################################################
    # Prints the results of the calculator in a sentence
        grossPayMSG = ("Your gross pay for {} hours is ${:.2f}." .format(hours, grossOver))
    # Condition for when hours are less than 40
    else:
        grossPay = hours * payRate
        overTime = 0
        ssTax = grossPay * 0.153
        fedTax = grossPay * 0.101
        stateTax = grossPay * 0.0447
        totalDeduct = ssTax + fedTax + stateTax + averageInsur
        netPay = grossPay - ssTax - fedTax - stateTax - averageInsur
        grossPayMSG = ("Your gross pay for {} hours is ${:.2f}." .format(hours, grossPay))
        
##########################################################################
# Invoice printer
# "\n" = line breaks
    clear_output()
    invoicePage = open("{}-{}-invoice.txt" .format(lastName, firstName), "w+") # Creates the invoice text file
    invoicePage.write ("Date: {}" .format(asctime())) # Adds creation date
    invoicePage.write ("\n")
    invoicePage.write ("Name: {} {}" .format(firstName, lastName)) # Every line of code below writes a line of text to the invoice
    invoicePage.write ("\n") 
    invoicePage.write ("Pay rate: ${:.2f}" .format(payRate))
    invoicePage.write ("\n")
    invoicePage.write ("Hours worked: {}" .format(hours))
    invoicePage.write ("\n")
    invoicePage.write ("---------------------------------")
    invoicePage.write ("\n")
    invoicePage.write ("{}" .format(grossPayMSG))
    invoicePage.write ("\n")
    invoicePage.write ("---------------------------------")
    invoicePage.write ("\n")
    invoicePage.write ("Deductions:")
    invoicePage.write ("\n")
    invoicePage.write ("FICA Tax: ${:.2f}" .format(ssTax))
    invoicePage.write ("\n")
    invoicePage.write ("State Tax: ${:.2f}" .format(stateTax))
    invoicePage.write ("\n")
    invoicePage.write ("Federal Tax: ${:.2f}" .format(fedTax))
    invoicePage.write ("\n")
    invoicePage.write ("Average cost of insurance: ${:.2f}" .format(averageInsur))
    invoicePage.write ("\n")
    invoicePage.write ("Total deductions: ${:.2f}" .format(totalDeduct))
    invoicePage.write ("\n")
    invoicePage.write ("Net pay: ${:.2f}" .format(netPay))
    invoicePage.close() 

    invoiceView = open("{}-{}-invoice.txt" .format(lastName, firstName), "r") # Prints and reads the invoice file
    viewFile = invoiceView.read
    print(viewFile())
    invoiceView.close()
    input("Press enter to continue.")
    clear_output()
##########################################################################
# Creates a menu to either enter the calculator or exit
def menu():
    while True:
        print("Welcome to the payroll calculator.")
        print("What would you like to do today?")
        print("----------------------------------")
        print("1. Calculate your pay")

        print("2. Exit")
        print("----------------------------------")
        menuChoice = input("Enter 1 or 2 here")

        if menuChoice == "1":
            calculatePay()
        elif menuChoice == "2": # Breaks out of the 'while True' loop
            print("See you later. :}")
            break
        else: # Returns user to menu if any answer that isn't 1 or 2 is entered
            print("I'm afraid I cant do that.")
            input("Press enter to return to the previous screen.")
            clear_output()
if __name__ == "__main__": # Loops the menu
    menu()
Date: Wed Mar  5 11:30:18 2025
Name: test user
Pay rate: $12.50
Hours worked: 46.0
---------------------------------
Your gross pay for 46.0 hours is $612.50.
---------------------------------
Deductions:
FICA Tax: $93.71
State Tax: $27.38
Federal Tax: $61.86
Average cost of insurance: $119.00
Total deductions: $301.95
Net pay: $310.55