Question: In Python, I want to re-enter a loop when an exception is caught. Above is my code. However, when I, say, enter a characer instead

 In Python, I want to re-enter a loop when an exception

In Python, I want to re-enter a loop when an exception is caught. Above is my code. However, when I, say, enter a characer instead of a float or int for hours worked, it throws off my results. Below is an example of the error I receive when I do so.

is caught. Above is my code. However, when I, say, enter a Can anyone help me with this? I'm guessing the coding is just wrong. How would I re-enter the initial loop if an exception is caught?

# create 3 lists ror employee name, their hours worked and their hourly rate of pay name) hours worked -[ hourly pay[n n - str(input ("Name (hit just enter when done) create an indefinite so the user cana the lists as such as while n !- name.append (n) try: hours float (input ("Ho worked: pay -rloat (input ("Hourly rate: ) print ("value must be numeric") hourly_pay.appe excent: elae nd (pay) hours vorked. append (hours) CEy: myfile open ("payroll, txt", "w") - except Totrror: print ("Error opening/writing to file) else 35 payroll-0 for i in range (len (name)): total - (Eormat (hours workedti hourly payti1 mytile.write (name [iJt myfile.write (str (hours worked[i])+t myfile.write(str (hourly payti]) nyfile.write (str (total)+"n) payrollt-float(total) Le myfile.write(" ") myfile.write("Total Payroll-str (payroll)+"n" avg payroll/len (name) mytile.write ("Average Paycheck+str (avg)) finally: yfile.close main 54

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!