In [ ]:
#Im importing this so I can clear the terminal screen
from IPython.display import clear_output

#this asks you for your first name
firstName = str(input("Enter your first name: "))
#this asks you for your last anme
lastName = str(input("Enter your last name: "))
#this asks you how much you get paid hourly
hourlyRate = int(input("What is your hourly rate?"))
#this asks you how much you got paid that day
numberOfHours = int(input("How many hours did you work?"))
#this is calculating the gross pay
grossPay = hourlyRate * numberOfHours
#this is calculating taxes
fedTax = grossPay * 0.1259
stateTax = grossPay * 0.482
ssTax = grossPay * 0.0765
#this tells you how much money you lost from taxes
totDeducts = fedTax + stateTax + ssTax
#this tells you your total pay for the day
netPay = grossPay - totDeducts
#this clears the screen
clear_output()
#this right here makes the actual file
file = open("{}-{}-paystub.txt", 'xt'.format(lastName, firstName))
file.close()
#this puts your first name on the file
file = open("{}-{}-paystub.txt", 'wt'.format(lastName, firstName))
file.write("First name: {}".format(firstName))
file.close()
#this puts your last name on the file
file = open("{}-{}-paystub.txt", 'at'.format(lastName, firstName))
file.write("\nLast Name: {}".format(lastName))
file.close()
#this tells you how much hours you worked for
file = open("{}-{}-paystub.txt", 'at'.format(lastName, firstName))
file.write("\n-------------------------------------\nYou worked for {} hours".format(numberOfHours))
file.close()
#this tells you how much you recieve each hour
file = open("{}-{}-paystub.txt", 'at'.format(lastName, firstName))
file.write("\nYou also have a {} hourly income".format(hourlyRate))
file.close()
#this tells you how much you got paid before taxes
file = open("{}-{}-paystub.txt", 'at'.format(lastName, firstName))
file.write("\n-------------------------------------\nGross Pay: {:.2f}".format(grossPay))
file.close()
#this tells you how much money you lost to taxes
file = open("{}-{}-paystub.txt", 'at'.format(lastName, firstName))
file.write("\nTotal deductions due to taxes: {:.2f}".format(totDeducts))
file.close()
#this tells you how much money you're getting paid after taxes
file = open("{}-{}-paystub.txt", 'at'.format(lastName, firstName))
file.write("\n-------------------------------------\nYour Total Pay comes to: {:.2f}".format(netPay))
#this just reads it in the file and prints it.
file = open("{}-{}-paystub.txt", 'rt'.format(lastName, firstName))
print(file.read())
file.close()
In [ ]:
 
In [49]:
#The code below specified the path the txt was located and returned only the first three characters
#testFile = open("/home/pi/Documents/test folder/pathTest.txt", "rt")
#print(testFile.read(3))

#The code below opened a txt file called test.txt and read it in the terminal
#textFile = open("test.txt", "rt")
#print(textFile.read())

#the code below created a txt file called open.txt, the x stands for create
#openFile = open("open.txt", "xt")

#the code below will print out the txt file one line at a time
#lineTest = open("readLine.txt", "rt")
#print(lineTest.readline())
#print(lineTest.readline())
#print(lineTest.readline())

#the code below will open a txt file, read it, then close it again. You should always close your files, in some cases, due to buffering, changes made to a file may not show until you close the file.
#closeTest = open("close.txt", "rt")
#print(closeTest.read())
#closeTest.close()

#There are two different ways to write with a file in python, there the append method, and the write method.
#The append method will add existing text or content to the end of the file.
#The write method will overwrite any existing content over the file

#the code below opened a txt file, added onto the text, closed it. Opened it back up again to read it, then closed it again.
#writeTest = open("write.txt", "at")
#writeTest.write(" Sure, i can do that")
#writeTest.close()

#writeTest = open("write.txt", "rt")
#print(writeTest.read())
#writeTest.close()


#The code below overwrited the text that was in the txt file, and closed. After it opened again to read itself to see if it has been overwritten.
#overwriteText = open("overwrite.txt", "wt")
#overwriteText.write("Damn, it's gone now")
#overwriteText.close()

#overwriteText = open("overwrite.txt", "rt")
#print(overwriteText.read())
#overwriteText.close()
In [ ]: