Question

PYTHON CODE First Code: Write a program that uses a text file to store the daysand...

PYTHON CODE

First Code:

Write a program that uses a text file to store the daysand 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

Second Code

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for the question,

For program 1 , i have commented the code so that you can follow the code and understand

======================================================================


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 ='hours.txt'
    with
open(filename,'w') as outfile:
        for i in range(len(daysName)):
            outfile.write('{} {}\n'.format(daysName[i],hoursWorked[i]))

    print('File was created)

main()

======================================================================

Code Screenshot, the file will be generated in the same directory where it contains the .py file

Add a comment
Know the answer?
Add Answer to:
PYTHON CODE First Code: Write a program that uses a text file to store the daysand...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need this program ASAP C++ language 1b. Write the implementation file timeClock.cpp for the class TimeClock....

    Need this program ASAP C++ language 1b. Write the implementation file timeClock.cpp for the class TimeClock. Com pile the file, and save it in the Chap 13 folder of your Student Data Files. 1c. Write a C++ program named weeklyPay.cpp to test your class Timeclock Your program should ask the user how many hours the user worked each day of the week. An object should be created for each day of the week with the number of hours for each...

  • THIS CODE SHOULD BE MODIFIED TO READ SuperMarket.dat instead of Inputting and Outputting. SuperMarket.dat Monday 4...

    THIS CODE SHOULD BE MODIFIED TO READ SuperMarket.dat instead of Inputting and Outputting. SuperMarket.dat Monday 4 Monday 6 Monday 2 Tuesday 3 Tuesday 2 Wednesday 3 Wednesday 5 Wednesday 7 Thursday 5 Friday 4 Friday 3 Friday 4 Saturday 8 Saturday 8 Saturday 8 Sunday 0 QUESTION: Write the control break code, including the code for the dayChange() method, in the main() method. // SuperMarket.java - This program creates a report that lists weekly hours worked // by employees of...

  • Your professor is hoping to get a summer job flipping burgers at the local burger joint....

    Your professor is hoping to get a summer job flipping burgers at the local burger joint. His starting salary will be $7.25 per hour. However, there are certain incentives to encourage him to work extra hours. It is calculated as follows per day: •$7.25 for the first 6 hours he works per day, Monday through Friday .•$8.25 for the next 2 hours he works per day, Monday through Friday. •$11.25 for each hour he works over 8 hours in a...

  • I need to write a program in java using two array lists. I need to program...

    I need to write a program in java using two array lists. I need to program to prompt the user to enter a day of the week and return an output of a predetermined temperature for the day they selected. I also need the program the output the average of daily temperatures across the week if the user inputs "week". So basically if i set the temperatures to something arbitrary i.e.: Monday = 50 Tuesday = 55 Wednesday = 52...

  • Coding in C++ Write a program using structures to store the following weather information: - Month...

    Coding in C++ Write a program using structures to store the following weather information: - Month name - Day of month (Monday, Tuesday, etc) - High Temperature - Low Temperature - Rainfall for the day Use an the input.txt file to load the data into weather structures. Once the data for all the days is entered, the program should calculate and display the: - Total rainfall for the data - Average daily temperatures. (note: you'll need to calculate the days...

  • week_days<- c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") How do i write a line of code...

    week_days<- c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") How do i write a line of code that will select the days Wednesday, Saturday, and Sunday in Rstudio?

  • LLC employs only salaried exempt individuals, who work a standard eight hours per day. One of...

    LLC employs only salaried exempt individuals, who work a standard eight hours per day. One of its employees worked more than eight hours on Monday, Wednesday, and Thursday, but did not work more than a total of 40 works during that week. What does FLSA say about the additional hours the employee worked on those single days? The employee will not be paid over time for the extra hours worked on Monday, Wednesday, and Thursday The employee must be paid...

  • Write a C++ Program. You have a following class as a header file (dayType.h) and main()....

    Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public:     static string weekDays[7];     void print() const;     string nextDay() const;     string prevDay() const;     void addDay(int nDays);     void setDay(string d);     string getDay() const;     dayType();     dayType(string d); private:     string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...

  • write this program in Java Problem 5. (30 Points) Write a program that reads employee work...

    write this program in Java Problem 5. (30 Points) Write a program that reads employee work data from a text file employee.txt), and then calculates payroll information based on this file and store them into a new text file called payroll.txt. The employee. txt file contains one line of text for each employee. Each line consists of the following data (delimited by tabs): employee's name, employee's hourly wage rate, hours worked Monday, hours worked Tuesday, hours worked Wednesday, hours worked...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT