In [1]:
#The Payroll Independent challenge!
#Created by Emanuel Vega
from IPython.display import clear_output #Imports clear screen command from the Display library

def GoAgain(): #A function that lets the user go again and restart
    Again = input("Would you like to add another paystub? Type y or n ==> ") #An input statement for the user
    if Again == "Y" or Again == "y": #A statement for if the user says yes in the input statement
        clear_output() #Clears the screen
        main() #Goes to the main function
    if Again == "N" or Again == "n": #A statement for if the user says no in the input statement
        print("Have a nice day!")
        exit() #Exits the program
    else:
        GoAgain() #Resets the GoAgain function if the user types anything other than yes or no
        
def main(): #The function for the main body of this program
    
    employeeFirst = input("Please put employees first name ==> ") #User inputs their first name here
    employeeLast = input("Please put employees last name ==> ") #User inputs their last name here
    
    employeePay = float(input("What is the employees hourly pay rate? ==> ")) #The float input that takes Hourly pay
    employeeHour = int(input("How many hours did they work this week? ==> ")) #The integer input that takes work hours
    clear_output() #Clears the screen
    
    grossPay = employeeHour * employeePay #grosspay variable equaling to the hours worked times the hourly pay
    federalTax = grossPay * .1259 #FederalTax variable equaling the grosspay times .1259
    stateTax = grossPay * .0482 #Statetax variable equaling the grosspay times .0482
    socialSecurity = grossPay * .0765 #SocialSecurity variable  equaling the grosspay times .0765
    
    totalDeductions = federalTax + stateTax + socialSecurity #totalDeductions variable equaling the sum of federal,state,and social taxes
    netPay = grossPay - totalDeductions #netpay variable equaling the grosspay minus the total deductions, the pay that the users will get
    
    payFile = open("{}-{}-paystub.txt".format(employeeLast, employeeFirst), "x") #creates a new text document titled after the users name
    
    payFile.close() #Closes the file after creating it
    
    writeFile = open("{}-{}-paystub.txt".format(employeeLast, employeeFirst), "w") #opens the text document so that it can be written into
    
    writeFile.write("Emanuel's Technological Institute\n") #writes into the document. this writes the fake company name i made up
    
    writeFile.write("----------------------------------\n") #This writes a line the seperates the text and makes it look nicer
    
    writeFile.write("Last Name: {} \n".format(employeeLast)) #This writes in the user's last name
    
    writeFile.write("First Name: {} \n".format(employeeFirst)) #This writes in the user's first name
    
    writeFile.write("Hourly Pay Rate: ${:.2f} \n".format(employeePay)) #This writes in the Employee pay rate
    
    writeFile.write("Worked {} Hours\n".format(employeeHour)) #This writes in the hours the user has worked
    
    writeFile.write("----------------------------------\n") #another line to seperate the text
    
    writeFile.write("Gross Pay: ${:.2f}\n".format(grossPay)) #This adds in the user's Gross Pay
    
    writeFile.write("Federal Tax: ${:.2f}\n".format(federalTax)) #This adds in the user's Federal Tax
    
    writeFile.write("State Tax: ${:.2f}\n".format(stateTax)) #This adds in the user's State tax
    
    writeFile.write("Social Security: ${:.2f}\n".format(socialSecurity)) #This adds in the user's Social Security
    
    writeFile.write("----------------------------------\n") #another line to seperate the text
    
    writeFile.write("Total Deductions: ${:.2f}\n".format(totalDeductions)) #This adds in the user's total deductions
    
    writeFile.write("Net Pay: ${:.2f}\n".format(netPay)) #adds the user's net pay!
    
    writeFile.write("Thanks for being a great employee!\n") #A sort of congratulations and thank you to the user
    
    writeFile.close() #Closes the file after writing in it
    
    print("Paystub has been created") #Tells the user that the paystub was created
    
    readFile = open("{}-{}-paystub.txt".format(employeeLast, employeeFirst), "r") #Opens the text document so that it can be read
    readFileOpen = readFile.read() #created an input that reads the text document
    print(readFileOpen) #prints the text document for the user to see
    readFile.close() #closes file after reading it
    GoAgain() #goes to the GoAgain function
    
main()
Paystub has been created
Emanuel's Technological Institute
----------------------------------
Last Name: Vega 
First Name: Emanuel 
Hourly Pay Rate: $48.00 
Worked 32 Hours
----------------------------------
Gross Pay: $1536.00
Federal Tax: $193.38
State Tax: $74.04
Social Security: $117.50
----------------------------------
Total Deductions: $384.92
Net Pay: $1151.08
Thanks for being a great employee!

Would you like to add another paystub? Type y or n ==> n
Have a nice day!