Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON CODE: write the second program Write a program that uses a text file to store the days and hours that a user worked in

PYTHON CODE: write the second program
Write a program that uses a text file to store the days and hours that a user worked in a week. The program should begin by prompting for the number of days worked in the week. It should continue with a loop for input of the days and hours and for writing these to the file, each on its own line.
Sample Output (inputs shown in boldface)
How many days did you work this week? 5
Enter day of week Monday
How many hours did you work on Monday? 10
Enter day of week Tuesday
How many hours did you work on Tuesday? 8
Enter day of week Wednesday
How many hours did you work on Wednesday? 12
Enter day of week Friday
How many hours did you work on Friday? 12
Enter day of week Saturday
How many hours did you work on Saturday? 8
File was created
Now write another program that reads the text file created in the program above and calculates the user's weekly pay. The program should begin by prompting the user for the regular hourly pay rate. The program should then loop through the file and report the days and hours worked. The program should finish by calling a custom void function named calc_pay that calculates and prints the weekly pay, including overtime, if applicable. By law, weekly hours in excess of 40 should be paid at 1.5 times the regular hourly rate. The calc_pay function takes two arguments, total hours and hourly pay rate, and it must be imported from a separate module file. Note that three outputs are required for the pay.
Sample Output 1
Enter your hourly pay rate 25.00
Here are your hours this week
Monday hours : 10.0
Tuesday hours : 8.0
Wednesday hours : 12.0
Friday hours : 12.0
Saturday hours : 8.0
You worked 50.0 hours this week
You worked 10.0 hours overtime
Your hourly pay rate is $25.00
Regular pay : $1,000.00
Overtime pay : $375.00
Total pay : $1,375.00
Sample Output 1 (for a different work week)
Enter your hourly pay rate 25.00
Here are your hours this week
Monday hours : 10.0
Wednesday hours : 12.0
Friday hours : 12.0
You worked 34.0 hours this week
Your hourly pay rate is $25.00
Regular pay : $850.00
Overtime pay : $0.00
Total pay : $850.00
this is the First code needed to do the second image text in transcribed
def main(): days Worked = int(input('How many days did you work this week?')) daysName=[] # will store the day names hours Worked=[] # will store the hours worked on that day #loop that many days prompting for day name and hours worked on that day for day in range(days Worked): dayName=input('Enter day of week:') hours = int(input('How many hours did you work on {}: '.format(dayName))) daysName.append(dayName) hours Worked.append(hours) #file that will be generated having the day name and hours on each line filename='hours.txt' with open(filename,'w') as outfile: for i in range(len(daysName)): outfile.write('$ f} '.format(daysName[i],hours Worked[i])) print('File was created) main() = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = Code Screenshot, the file will be generated in the same directory where it contains the .py file def main(): daysWorked = int(input ("How many days did you work this week? )) daysName=[] # will store the day names hoursWorked=[] # will store the hours worked on that day # loop that many days prompting for day name and hours worked on that day for day in range (daysWorked): dayName = input ("Enter day of week: ") hours = int(input ("How many hours did you work on (): '. format (dayName))) daysName. append (dayName) hoursworked. append (hours) # file that will be generated having the day name and hours on each line filename='D:\\hours.txt' with open(filename, 'W') as outfile: for i in range (len (daysName)): outfile.write('O '. format (daysName[i], hoursWorked[i])) main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions