SlideShare a Scribd company logo
from datetime import datetime
##############################################################################
##
def CreateUsers():
print('##### Create users, passwords, and roles #####')
########## Open the file user.txt in append mode and assign to UserFile
while True:
########## Write the line of code that will call function GetUserName and assign the return value
to username
if (username.upper() == "END"):
break
########## Write the line of code that will call function GetUserPassword and assign the return
value to userpwd
########## Write the line of code that will call function GetUserRole() and assign the return value
to userrole
UserDetail = username + "|" + userpwd + "|" + userrole + "n"
UserFile.write(UserDetail)
# close file to save data
########## Write the line of code that will close the file UserFile
def GetUserName():
##### write the code to enter the username or End and return username
def GetUserPassword():
##### write the code to enter the pwd and return pwd
def GetUserRole():
userrole = input("Enter role (Admin or User): ")
while True:
####### write the if statement that validates that Admin or User has been entered. If true, return
userrole. If false, re-input userrole
def printuserinfo():
UserFile = open("Users.txt","r")
while True:
UserDetail = UserFile.readline()
if not UserDetail:
break
UserDetail = UserDetail.replace("n", "") #remove carriage return from end of line
UserList = UserDetail.split("|")
username = UserList[0]
userpassword = UserList[1]
userrole = UserList[2]
print("User Name: ", username, " Password: ", userpassword, " Role: ", userrole)
##############################################################################
##############
def Login():
# read login information and store in a list
########## Write the line of code that will open the file Users.txt in read mode
UserName = input("Enter User Name: ")
UserRole = "None"
while True:
########## Write the line of code that will read a line from UserFile and assign it to UserDetail
if not UserDetail:
return UserRole, UserName
########## Write the line of code that will replace the carriage return in UserDetail
########## Write the line of code that will split UserDetail on the pipe delimiter (|) and assign it to
UserList
if UserName == UserList[0]:
UserRole = UserList[2] # user is valid, return role
return UserRole, UserName
return UserRole, UserName
##############################################################################
###########
def GetEmpName():
empname = input("Enter employee name: ")
return empname
def GetDatesWorked():
fromdate = input("Enter Start Date (mm/dd/yyyy: ")
todate = input("Enter End Date (mm/dd/yyyy: ")
return fromdate, todate
def GetHoursWorked():
hours = float(input('Enter amount of hours worked: '))
return hours
def GetHourlyRate():
hourlyrate = float(input ("Enter hourly rate: "))
return hourlyrate
def GetTaxRate():
taxrate = float(input ("Enter tax rate: "))
return taxrate
def CalcTaxAndNetPay(hours, hourlyrate, taxrate):
grosspay = hours * hourlyrate
incometax = grosspay * taxrate
netpay = grosspay - incometax
return grosspay, incometax, netpay
def printinfo(DetailsPrinted):
TotEmployees = 0
TotHours = 0.00
TotGrossPay = 0.00
TotTax = 0.00
TotNetPay = 0.00
EmpFile = open("Employees.txt","r")
while True:
rundate = input ("Enter start date for report (MM/DD/YYYY) or All for all data in file: ")
if (rundate.upper() == "ALL"):
break
try:
rundate = datetime.strptime(rundate, "%m/%d/%Y")
break
except ValueError:
print("Invalid date format. Try again.")
print()
continue # skip next if statement and re-start loop
while True:
EmpDetail = EmpFile.readline()
if not EmpDetail:
break
EmpDetail = EmpDetail.replace("n", "") #remove carriage return from end of line
EmpList = EmpDetail.split("|")
fromdate = EmpList[0]
if (str(rundate).upper() != "ALL"):
checkdate = datetime.strptime(fromdate, "%m/%d/%Y")
if (checkdate < rundate):
continue
todate = EmpList[1]
empname = EmpList[2]
hours = float(EmpList[3])
hourlyrate = float(EmpList[4])
taxrate = float(EmpList[5])
grosspay, incometax, netpay = CalcTaxAndNetPay(hours, hourlyrate, taxrate)
print(fromdate, todate, empname, f"{hours:,.2f}", f"{hourlyrate:,.2f}", f"{grosspay:,.2f}",
f"{taxrate:,.1%}", f"{incometax:,.2f}", f"{netpay:,.2f}")
TotEmployees += 1
TotHours += hours
TotGrossPay += grosspay
TotTax += incometax
TotNetPay += netpay
EmpTotals["TotEmp"] = TotEmployees
EmpTotals["TotHrs"] = TotHours
EmpTotals["TotGrossPay"] = TotGrossPay
EmpTotals["TotTax"] = TotTax
EmpTotals["TotNetPay"] = TotNetPay
DetailsPrinted = True
if (DetailsPrinted): #skip of no detail lines printed
PrintTotals (EmpTotals)
else:
print("No detail information to print")
def PrintTotals(EmpTotals):
print()
print(f'Total Number Of Employees: {EmpTotals["TotEmp"]}')
print(f'Total Hours Worked: {EmpTotals["TotHrs"]:,.2f}')
print(f'Total Gross Pay: {EmpTotals["TotGrossPay"]:,.2f}')
print(f'Total Income Tax: {EmpTotals["TotTax"]:,.2f}')
print(f'Total Net Pay: {EmpTotals["TotNetPay"]:,.2f}')
if __name__ == "__main__":
##################################################
########## Write the line of code to call the method CreateUsers
print()
print("##### Data Entry #####")
########## Write the line of code to assign UserRole and UserName to the function Login
DetailsPrinted = False ###
EmpTotals = {} ###
########## Write the if statement that will check to see if UserRole is equal to NONE (NOTE:
code will show red error lines until this line is written)
print(UserName," is invalid.")
else:
# only admin users can enter data
##### write the if statement that will check to see if the UserRole is equal to ADMIN (NOTE: code
will show red error lines until this line is written)
EmpFile = open("Employees.txt", "a+")
while True:
empname = GetEmpName()
if (empname.upper() == "END"):
break
fromdate, todate = GetDatesWorked()
hours = GetHoursWorked()
hourlyrate = GetHourlyRate()
taxrate = GetTaxRate()
EmpDetail = fromdate + "|" + todate + "|" + empname + "|" + str(hours) + "|" + str(hourlyrate) + "|" +
str(taxrate) + "n"
EmpFile.write(EmpDetail)
# close file to save data
EmpFile.close()
printinfo(DetailsPrinted)

More Related Content

PDF
from datetime import datetime def CreateUsers()- print('##### Crea.pdf
PDF
RubyBarCamp “Полезные gems и plugins”
PDF
lab-assgn-practical-file-xii-cs.pdf
PDF
25 MARCH1 list, generator.pdf list generator
PDF
So basically I worked really hard on this code in my CS150 class and.pdf
PPTX
Unit2 input output
PDF
C++ Nested loops, matrix and fuctions.pdf
PDF
python.pdf
from datetime import datetime def CreateUsers()- print('##### Crea.pdf
RubyBarCamp “Полезные gems и plugins”
lab-assgn-practical-file-xii-cs.pdf
25 MARCH1 list, generator.pdf list generator
So basically I worked really hard on this code in my CS150 class and.pdf
Unit2 input output
C++ Nested loops, matrix and fuctions.pdf
python.pdf

Similar to from datetime import datetime .pdf (20)

PDF
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
PPT
2.overview of c++ ________lecture2
PPTX
Learning to code with Python! (Microsoft Virtual Academy).pptx
PPTX
Learning to code with Python! (MVA).pptx
PDF
General Functions
PDF
intro_to_python_20150825
PDF
python.pdf
PDF
Developer Experience i TypeScript. Najbardziej ikoniczne duo
PDF
Practical TypeScript
PDF
Computer Science chapter 7 functions class 12
PDF
ECMAScript2015
PPTX
Django - sql alchemy - jquery
PDF
Elixir in a nutshell - Fundamental Concepts
PDF
Controller specs
PDF
python_lab_manual_final (1).pdf
DOCX
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PDF
Python Training Course in Chandigarh(Mohali)
PDF
Python Training in Chandigarh(Mohali)
PPTX
CLASS-11 & 12 ICT PPT PYTHON PROGRAMMING.pptx
PPTX
Type Driven Development with TypeScript
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
2.overview of c++ ________lecture2
Learning to code with Python! (Microsoft Virtual Academy).pptx
Learning to code with Python! (MVA).pptx
General Functions
intro_to_python_20150825
python.pdf
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Practical TypeScript
Computer Science chapter 7 functions class 12
ECMAScript2015
Django - sql alchemy - jquery
Elixir in a nutshell - Fundamental Concepts
Controller specs
python_lab_manual_final (1).pdf
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
Python Training Course in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)
CLASS-11 & 12 ICT PPT PYTHON PROGRAMMING.pptx
Type Driven Development with TypeScript
Ad

More from sachinactivepower (20)

PDF
From the case study the rise and fall of blackberry Debor.pdf
PDF
Fordham bronx What are possible potential interventions fo.pdf
PDF
From The Effect You are interested in the effect of cultur.pdf
PDF
From David Schwimmers article on dinosaur occurrences in th.pdf
PDF
From a scientific standpoint much of the controversy around.pdf
PDF
freoare a talet bosaet teas Junetient Sales iluatoet Jor the.pdf
PDF
Frenzied cruise vacationers besiege Tatiana their excursion.pdf
PDF
Frank Pepe sigue una estrategia nica en la que regala pizza.pdf
PDF
Fred drives a truck for Ted for which he has a CDL Fred lea.pdf
PDF
Freddy was in love with three girls from his school He coul.pdf
PDF
Frankie is a merchant in the business of repairing and selli.pdf
PDF
fp4 Sources of Heat Sources of Heat Lets look at how this.pdf
PDF
Four people are sharing a house They like cake X which i.pdf
PDF
Four major areas of ethical values influence managers Thes.pdf
PDF
Four distributions labeled a b c and d are repre.pdf
PDF
Four members from a 59person committee are to be selected r.pdf
PDF
Four buses carrying 156 high school students arrive to Montr.pdf
PDF
fossils indicate that protostome lineages originated in the .pdf
PDF
For this task you will identify a publicly available datase.pdf
PDF
For this assignment you will write 1000 words about any cha.pdf
From the case study the rise and fall of blackberry Debor.pdf
Fordham bronx What are possible potential interventions fo.pdf
From The Effect You are interested in the effect of cultur.pdf
From David Schwimmers article on dinosaur occurrences in th.pdf
From a scientific standpoint much of the controversy around.pdf
freoare a talet bosaet teas Junetient Sales iluatoet Jor the.pdf
Frenzied cruise vacationers besiege Tatiana their excursion.pdf
Frank Pepe sigue una estrategia nica en la que regala pizza.pdf
Fred drives a truck for Ted for which he has a CDL Fred lea.pdf
Freddy was in love with three girls from his school He coul.pdf
Frankie is a merchant in the business of repairing and selli.pdf
fp4 Sources of Heat Sources of Heat Lets look at how this.pdf
Four people are sharing a house They like cake X which i.pdf
Four major areas of ethical values influence managers Thes.pdf
Four distributions labeled a b c and d are repre.pdf
Four members from a 59person committee are to be selected r.pdf
Four buses carrying 156 high school students arrive to Montr.pdf
fossils indicate that protostome lineages originated in the .pdf
For this task you will identify a publicly available datase.pdf
For this assignment you will write 1000 words about any cha.pdf
Ad

Recently uploaded (20)

PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PPTX
Computer Architecture Input Output Memory.pptx
PDF
1_English_Language_Set_2.pdf probationary
PDF
Empowerment Technology for Senior High School Guide
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Trump Administration's workforce development strategy
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Introduction to Building Materials
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
20th Century Theater, Methods, History.pptx
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
Computer Architecture Input Output Memory.pptx
1_English_Language_Set_2.pdf probationary
Empowerment Technology for Senior High School Guide
Practical Manual AGRO-233 Principles and Practices of Natural Farming
FORM 1 BIOLOGY MIND MAPS and their schemes
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Trump Administration's workforce development strategy
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
Weekly quiz Compilation Jan -July 25.pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Introduction to Building Materials
Chinmaya Tiranga quiz Grand Finale.pdf
20th Century Theater, Methods, History.pptx
ChatGPT for Dummies - Pam Baker Ccesa007.pdf

from datetime import datetime .pdf

  • 1. from datetime import datetime ############################################################################## ## def CreateUsers(): print('##### Create users, passwords, and roles #####') ########## Open the file user.txt in append mode and assign to UserFile while True: ########## Write the line of code that will call function GetUserName and assign the return value to username if (username.upper() == "END"): break ########## Write the line of code that will call function GetUserPassword and assign the return value to userpwd ########## Write the line of code that will call function GetUserRole() and assign the return value to userrole UserDetail = username + "|" + userpwd + "|" + userrole + "n" UserFile.write(UserDetail) # close file to save data ########## Write the line of code that will close the file UserFile def GetUserName(): ##### write the code to enter the username or End and return username def GetUserPassword(): ##### write the code to enter the pwd and return pwd def GetUserRole(): userrole = input("Enter role (Admin or User): ") while True: ####### write the if statement that validates that Admin or User has been entered. If true, return userrole. If false, re-input userrole def printuserinfo(): UserFile = open("Users.txt","r") while True: UserDetail = UserFile.readline() if not UserDetail: break UserDetail = UserDetail.replace("n", "") #remove carriage return from end of line UserList = UserDetail.split("|") username = UserList[0]
  • 2. userpassword = UserList[1] userrole = UserList[2] print("User Name: ", username, " Password: ", userpassword, " Role: ", userrole) ############################################################################## ############## def Login(): # read login information and store in a list ########## Write the line of code that will open the file Users.txt in read mode UserName = input("Enter User Name: ") UserRole = "None" while True: ########## Write the line of code that will read a line from UserFile and assign it to UserDetail if not UserDetail: return UserRole, UserName ########## Write the line of code that will replace the carriage return in UserDetail ########## Write the line of code that will split UserDetail on the pipe delimiter (|) and assign it to UserList if UserName == UserList[0]: UserRole = UserList[2] # user is valid, return role return UserRole, UserName return UserRole, UserName ############################################################################## ########### def GetEmpName(): empname = input("Enter employee name: ") return empname def GetDatesWorked(): fromdate = input("Enter Start Date (mm/dd/yyyy: ") todate = input("Enter End Date (mm/dd/yyyy: ") return fromdate, todate def GetHoursWorked(): hours = float(input('Enter amount of hours worked: ')) return hours def GetHourlyRate(): hourlyrate = float(input ("Enter hourly rate: ")) return hourlyrate def GetTaxRate():
  • 3. taxrate = float(input ("Enter tax rate: ")) return taxrate def CalcTaxAndNetPay(hours, hourlyrate, taxrate): grosspay = hours * hourlyrate incometax = grosspay * taxrate netpay = grosspay - incometax return grosspay, incometax, netpay def printinfo(DetailsPrinted): TotEmployees = 0 TotHours = 0.00 TotGrossPay = 0.00 TotTax = 0.00 TotNetPay = 0.00 EmpFile = open("Employees.txt","r") while True: rundate = input ("Enter start date for report (MM/DD/YYYY) or All for all data in file: ") if (rundate.upper() == "ALL"): break try: rundate = datetime.strptime(rundate, "%m/%d/%Y") break except ValueError: print("Invalid date format. Try again.") print() continue # skip next if statement and re-start loop while True: EmpDetail = EmpFile.readline() if not EmpDetail: break EmpDetail = EmpDetail.replace("n", "") #remove carriage return from end of line EmpList = EmpDetail.split("|") fromdate = EmpList[0] if (str(rundate).upper() != "ALL"): checkdate = datetime.strptime(fromdate, "%m/%d/%Y") if (checkdate < rundate): continue todate = EmpList[1] empname = EmpList[2] hours = float(EmpList[3]) hourlyrate = float(EmpList[4]) taxrate = float(EmpList[5]) grosspay, incometax, netpay = CalcTaxAndNetPay(hours, hourlyrate, taxrate)
  • 4. print(fromdate, todate, empname, f"{hours:,.2f}", f"{hourlyrate:,.2f}", f"{grosspay:,.2f}", f"{taxrate:,.1%}", f"{incometax:,.2f}", f"{netpay:,.2f}") TotEmployees += 1 TotHours += hours TotGrossPay += grosspay TotTax += incometax TotNetPay += netpay EmpTotals["TotEmp"] = TotEmployees EmpTotals["TotHrs"] = TotHours EmpTotals["TotGrossPay"] = TotGrossPay EmpTotals["TotTax"] = TotTax EmpTotals["TotNetPay"] = TotNetPay DetailsPrinted = True if (DetailsPrinted): #skip of no detail lines printed PrintTotals (EmpTotals) else: print("No detail information to print") def PrintTotals(EmpTotals): print() print(f'Total Number Of Employees: {EmpTotals["TotEmp"]}') print(f'Total Hours Worked: {EmpTotals["TotHrs"]:,.2f}') print(f'Total Gross Pay: {EmpTotals["TotGrossPay"]:,.2f}') print(f'Total Income Tax: {EmpTotals["TotTax"]:,.2f}') print(f'Total Net Pay: {EmpTotals["TotNetPay"]:,.2f}') if __name__ == "__main__": ################################################## ########## Write the line of code to call the method CreateUsers print() print("##### Data Entry #####") ########## Write the line of code to assign UserRole and UserName to the function Login DetailsPrinted = False ### EmpTotals = {} ### ########## Write the if statement that will check to see if UserRole is equal to NONE (NOTE: code will show red error lines until this line is written) print(UserName," is invalid.") else: # only admin users can enter data ##### write the if statement that will check to see if the UserRole is equal to ADMIN (NOTE: code
  • 5. will show red error lines until this line is written) EmpFile = open("Employees.txt", "a+") while True: empname = GetEmpName() if (empname.upper() == "END"): break fromdate, todate = GetDatesWorked() hours = GetHoursWorked() hourlyrate = GetHourlyRate() taxrate = GetTaxRate() EmpDetail = fromdate + "|" + todate + "|" + empname + "|" + str(hours) + "|" + str(hourlyrate) + "|" + str(taxrate) + "n" EmpFile.write(EmpDetail) # close file to save data EmpFile.close() printinfo(DetailsPrinted)