Question: 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
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
Get step-by-step solutions from verified subject matter experts
