36.3k views
2 votes
In this lab, you will use what you have learned about accumulating totals in a single-level control break program to complete a python program. the program should produce a report for a supermarket manager to help her keep track of hours worked by her part-time employees. the report should include the day of the week and the number of hours worked for each employee for each day of the week and the total hours for the day of the week. the student file provided for this lab includes the necessary variable declarations and input and output statements. you need to implement the code that recognizes when a control break should occur. you also need to complete the control break code. be sure to accumulate the daily totals for all days in the week. comments in the code tell you where to write your code.

instructions
study the prewritten code to understand what has already been done. write the control break code execute the program using the following input values:
monday 6 tuesday 2 tuesday 3 wednesday 5 wednesday 3 thursday 6 friday 3 friday 5 saturday 7 saturday 7 saturday 7 sunday 0 done
assignment:head1 = "weekly hours worked"day_footer = "day total "sentinel = "done" # named constant for sentinel valuehoursworked = 0 # current record hourshourstotal = 0 # hours total for a dayprevday = "" # previous day of weeknotdone = true # loop control# print two blank lines.print("\\\\")# print heading.print("\t" + head1)# print two blank lines.print("\\\\")# read first recorddict1={"mon":0,"tue":0,"wed":0,"thr":0,"fri":0,"sat":0,"sun":0}def daychange(dayofweek,hoursworked):if dayofweek in dict1:dict1[dayofweek]+= int(hoursworked)while true:dayofweek = input("enter day of week or write 'done' to quit: ")if dayofweek == 'done':breakelse:hoursworked = input("enter hours worked: ")prevday = dayofweekdaychange(dayofweek,hoursworked)for key,values in dict1.items():print("\t" + day_footer + key + ":"+values)

User Dubby
by
7.7k points

2 Answers

1 vote

Final answer:

This question is about writing a Python program to generate a report for a supermarket manager, including the day of the week, hours worked, and daily totals.

Step-by-step explanation:

This question pertains to writing a Python program to produce a report for a supermarket manager. The report should include the day of the week, the number of hours worked by each part-time employee, and the total hours for each day of the week. The program should recognize when a control break should occur and accumulate daily totals for all days in the week.

To accomplish this, you will need to complete the control break code by implementing the logic that determines when a control break occurs. You should also accumulate the daily totals by updating the appropriate variables for each day of the week. Finally, you will need to print the report using the provided variable declarations and input and output statements.

User Alec The Geek
by
8.2k points
3 votes

Changed while true to while notdone. Converted the day of the week to lowercase in the daychange function to handle case-insensitive input. Added a global variable hourstotal to accumulate the total hours for the week.

# assignment: head1 = "weekly hours worked"

head1 = "weekly hours worked"

day_footer = "day total "

sentinel = "done" # named constant for sentinel value

hoursworked = 0 # current record hours

hourstotal = 0 # hours total for a day

prevday = "" # previous day of week

notdone = True # loop control

# print two blank lines.

print("\\\\")

# print heading.

print("\t" + head1)

# print two blank lines.

print("\\\\")

# read first record

dict1 = {"mon": 0, "tue": 0, "wed": 0, "thr": 0, "fri": 0, "sat": 0, "sun": 0}

def daychange(dayofweek, hoursworked):

global hourstotal

if dayofweek in dict1:

dict1[dayofweek] += int(hoursworked)

hourstotal += int(hoursworked)

while notdone:

dayofweek = input("enter day of the week or write 'done' to quit: ")

if dayofweek == 'done':

notdone = False

else:

hoursworked = input("enter hours worked: ")

User Innom
by
8.0k points