In [2]:
from time import asctime # I import asctime() from the library
from IPython.display import clear_output

def calculatepay():
    ###########################################
     #variable delcoration'

   FirstName=input("Enter your first name")# I enter my first name
   LastName=input("Enter your Last name")# I enter my last name
   payrate=float(input("How much do you get paid an hour?"))# I enter how much I get paid an hour
   hours=float(input("How many hours have you worked?"))# I enter how many hours i've worked this week


   fedtaxrate= 0.101 # 10.1% for the fed


   statetaxrate= 0.0447 # 4.47% for the state


   socialsecurity= 0.153 # 15.3% for soc sec, and medicare


   insurance= 119.08 # ct charge is $119.08

   ############################################################################################################
   #If I work greater than 40 hours, I multiply my base pay by 40, subtract total hours worked by 40
   #giving me my overtime hours
   #I then take my payrate multiply by 1.1 giving me my time and a half
   #multiply that time and a half  to my overtime hours, and then my pay for hours worked is the overtime pay

   if hours > 40.00:
    basepay = payrate + 40
    overhours = hours - 40
    overtime = (payrate + 1.5) * overhours
    grosspay = basepay + overtime

    grosspaymessage = "\n\nYour gross pay for {:.2f}".format(hours, grosspay)
       
   else:
    grosspay = payrate * hours
    overhours = 0.0
    overtime = 0.0
   ############################################################################################################'
    # here is where my delcorations are figured

    fedtaxpaid = fedtaxrate * grosspay
#I create a variable called fedtaxpay that multiplies the fed tax
                                      #rate variable by my gross pay figured out is the if statement
    
    statetaxpaid = statetaxrate * grosspay  # I create a variable called Statetaxpay that multiplies the state tax
                                      #rate  variable by my gross pay figured out is the if statement

    socialsecuritypaid = socialsecurity * grosspay  # I create a variable called socialsecuritypay that multiplies the social secuirty tax
                                      #rate  variable by my gross pay figured out is the if statement

    totaldeduction = fedtaxpaid + statetaxpaid + socialsecuritypaid + insurance #here I will add all of my
                                                                                #Deductions
    netpay = grosspay - totaldeduction # 

    print(FirstName, LastName, payrate, hours, fedtaxpaid,  statetaxpaid,  socialsecuritypaid, totaldeduction, insurance)
    print(netpay, overtime, overhours, grosspay)
#############################################################################################################################################

    invoicePage = open("{}-{}-invoice.txt".format(LastName, FirstName), "w+" )

    invoicePage.write("\n")
    invoicePage.write(" Pay for {} {}".format(LastName, FirstName))
    invoicePage.write("\n")
    invoicePage.write("Payrate: ${:.2f}".format(payrate))
    invoicePage.write("\n")
    invoicePage.write("Total hours worked {}".format(hours))
    invoicePage.write("\n")
    invoicePage.write("Overtime hours at time and a half: {:.2f}".format(overhours))
    invoicePage.write("\n")
    invoicePage.write("Date/Time report was run {}".format(asctime()))
    invoicePage.write("\n")
    invoicePage.write("Deductions\n")
    invoicePage.write("----------------------------\n")
    invoicePage.write("Federal Income Tax: {:.2f}\n".format(fedtaxpaid))
    invoicePage.write("\n")
    invoicePage.write("State of CT Income Tax: {:.2f}\n".format(statetaxpaid))
    invoicePage.write("\n")
    invoicePage.write("Social security: ${:.2f}\n".format(socialsecuritypaid)) 
    invoicePage.write("\n")
    invoicePage.write("Insurance: ${:.2f}\n".format(insurance))
    invoicePage.write("\n")
    invoicePage.write("Total Deductions: {:.2f}\n".format(totaldeduction))
    invoicePage.write("----------------------------\n\n")
    invoicePage.write("Total pay recieved is ${:.2f}\n".format(netpay))
    invoicePage.close()

    invoiceView = open("{}-{}-invoice.txt".format(LastName, FirstName), "r" )
    viewfile = invoiceView.read()
    print(viewfile)
    invoiceView.close()

       
    print("---------------------->")
    input("press enter to continue")
    print("---------------------->")
##########################################################################################
def menu():
   
    while True:
     print("welcome to payroll calculator")
     print(" what dp you want to do?")
     print("---------------------->")
     print(" 1. calculate pay")
     print(" 2. exit")
     print("---------------------->")

     menuchoice = input("Enter your choice(1 or 2)")
     print("---------------------->")
        
     if menuchoice == "1":
          calculatepay()
     elif menuchoice == "2":
         print("Have a nice day")
         break
     else:
         print("")
         input("Press enter")
         clear_output()

if __name__ == "__main__":
    menu()
welcome to payroll calculator
 what dp you want to do?
---------------------->
 1. calculate pay
 2. exit
---------------------->
---------------------->
Miguel Robles 889.0 39.98 3589.7642199999996 1588.7372339999997 5437.959659999999 10735.541113999998 119.08
24806.678885999994 0.0 0.0 35542.219999999994

 Pay for Robles Miguel
Payrate: $889.00
Total hours worked 39.98
Overtime hours at time and a half: 0.00
Date/Time report was run Fri Mar  7 08:13:00 2025
Deductions
----------------------------
Federal Income Tax: 3589.76

State of CT Income Tax: 1588.74

Social security: $5437.96

Insurance: $119.08

Total Deductions: 10735.54
----------------------------

Total pay recieved is $24806.68

---------------------->
---------------------->
welcome to payroll calculator
 what dp you want to do?
---------------------->
 1. calculate pay
 2. exit
---------------------->
---------------------->
Have a nice day
In [ ]: