In [ ]:
from IPython.display import clear_output
from time import asctime

def calculate_Pay():
    #######################################################################################################
    #declare variables
    firstName = input("whats your first name?") #Enter first name
    lastName = input("Whats your last name?") # Enter last name
    payRate = float(input("Whats your pay rate?")) #Enter how much you make a hour
    hours = float(input("How many hours do you work?")) #Enter hours you worked this week

    fedTaxRate = .101 #10.1% for fed

    stateTaxRate = 0.0447 #4.47% for the state

    socialSercuity = .153 #15.3% for soc,sec abd medicare

    insurance = 119.00 #Ct average is $119.00

    print(firstName, lastName, payRate, hours, fedTaxRate, stateTaxRate,  socialSercuity, insurance)
    
    #If I work greater 40 hours. I multiply my base pay by 40, subtract total hours by 40,
    #giving me my overtime hours
    #I then take my payrate multiply by 1.5 giving me my time and a half
    #Multiply that time and half by my overtime hours,and then add my pay for hours worked to the overtime pay
    
    if hours > 40.00:
        basePay = payRate * 40
        overHours = hours - 40

        overTime = (payRate * 1.5) * overHours
        grossPay = basePay + overTime
    else:
        grossPay = payRate * hours
        overHours = 0.0

    #Here is where deduction are figured

    fedTaxPaid = fedTaxRate * grossPay #Creates a variable called fedTaxPaid that multiplies the fed tax rate
                                       # by the gross pay figured out in the if statment
    
    stateTaxPaid = stateTaxRate * grossPay #Creates a variable called stateTaxPaid that multiplies the state tax rate
                                           # by the gross pay figured out in the if statment

    socialSercuityPaid = socialSercuity * grossPay #Creates a variable called socialSercuityPaid that multiplies the social sercuity tax rate
                                                   # by the gross pay figured out in the if statment

    totalDeductions = fedTaxPaid + stateTaxPaid + socialSercuityPaid + insurance # Add up all deductions
    
    netPay = grossPay - totalDeductions #netPay variable is where grosspay is taken and subtract all deductions

    invoicePage = open("{}-{}-invoice.txt".format(lastName, firstName), "w") #Open a invoice page and overwrite it so we can write on it
    
    invoicePage.write("\n") #Creates new line
    invoicePage.write("Pay for {}-{}".format(lastName, firstName)) #Writes the last and first name
    invoicePage.write("\n") #Creates new line
    invoicePage.write("Payrate: ${:.2f}".format(payRate)) #Writes the payRate
    invoicePage.write("\n") #Creates new line
    invoicePage.write("Total hours worked {}".format(hours)) #Write hours worked
    invoicePage.write("\n") #Creates new line
    invoicePage.write("Overtime hours at time and a half: {:.2f}".format(overHours)) #Write overHours
    invoicePage.write("\n") #Creates new line
    invoicePage.write("Date/time report was run {}".format(asctime())) #Writes the time when the payroll was ran
    invoicePage.write("\n") #Creates new line
    invoicePage.write("Your gorsspay is {} and your hours are {}".format(grossPay,hours)) #Writes grossPay and hours
    invoicePage.write("\n") #Creates new line
    invoicePage.write("Deductions\n") #Writes Deductions
    invoicePage.write("...................................\n") #Writes a bunch of periods to sperate the Deductions
    invoicePage.write("Federal Income Tax ${:.2f}".format(fedTaxPaid)) #Writes how much they spend on federal income tax
    invoicePage.write("\n") #Creates new line
    invoicePage.write("State is CT Income Tax: ${:.2f}".format(stateTaxRate)) #Writes how much they spend on CT income tax
    invoicePage.write("\n") #Creates new line
    invoicePage.write("Social Sercuity Income Tax: ${:.2f}".format(socialSercuityPaid)) #Writes how much they spend on Social Sercuity Income income tax
    invoicePage.write("\n") #Creates new line
    invoicePage.write("Insurance: ${:.2f}".format(insurance)) #Writes how much they spend on insurance income tax
    invoicePage.write("\n") #Creates new line
    invoicePage.write("Total Deductions: ${:.2f}".format(totalDeductions)) #Writes totalDeductions
    invoicePage.write("...................................\n\n") #Writes a bunch of periods to sperate the netPay
    invoicePage.write("Total pay received is: ${:.2f}".format(netPay)) #Writes the netPay

    invoicePage.close #Closes the invoicePage

    invoiceView = open("{}-{}-invoice.txt".format(lastName, firstName), "r") #Open the invoice text and lets us read it
    invoiceViewRead=invoiceView.read() #Read invoicetime is stored in invoiceViewRead
    print(invoiceViewRead) #Prints invoiceViewRead to show the invoicePage

    invoiceView.close() #Closes invoiceView

def menu(): #A menu function so the user can choice to use the payroll or exit
    while True: #Forever
        print("Welcome to the payroll calculater") #Prints welcome message
        print("   What would you like to do?") #Asking the user what do they want to do
        print("1. Calculate payroll") #Tells them 1 to use the payroll
        print("2. Exit") #Tells them 2 to exit

        choice=input("Choice 1 or 2") #Prompts the user to pick 1 or 2

        if choice == "1": #If they pick 1
            calculate_Pay() #We call the calculate_Pay function to find their payroll
        elif choice == "2": #If they pick 2
            print("Have a nice day :D") #Prints a good message
            break #Exits the While True loop
        else: #If they put a invalid option
            print("Invalid choice, choose") #Prints its a invalid option
            input("Press enter") #Wait for them to press enter
            clear_output() #Clears the output and repeats the loop
            
if __name__ == "__main__": #__main__ is created by the prgroam automatically  and this if statement prevents librarys from taking control
    menu() #Calls the menu function
Welcome to the payroll calculater
   What would you like to do?
1. Calculate payroll
2. Exit
John Doe 45.0 43.0 0.101 0.0447 0.153 119.0

Pay for Doe-John
Payrate: $45.00
Total hours worked 43.0
Overtime hours at time and a half: 3.00
Date/time report was run Wed Mar  5 11:46:00 2025
Your gorsspay is 2002.5 and your hours are 43.0
Deductions
...................................

Federal Income Tax $202.25

State is CT Income Tax: $0.04
Social Sercuity Income Tax: $306.38
Insurance: $119.00
Total Deductions: $717.15...................................

Total pay received is: $1285.35
Welcome to the payroll calculater
   What would you like to do?
1. Calculate payroll
2. Exit
In [ ]: