Oct-26-2020, 01:59 AM
(This post was last modified: Oct-26-2020, 01:59 AM by MahaEbrahim.)
Dear All,
The program is supposed to calculate the hour rate paid if there is an overtime and continue normally if not.
but the added while loop and try except in case there is a wrong input from the user. the user can try two times before the program closes.
The program runs except for the else part in the except . It suppose to print (close program) and quit once the user tried twice to add the input . but instead it shows the following error.
The program is supposed to calculate the hour rate paid if there is an overtime and continue normally if not.
but the added while loop and try except in case there is a wrong input from the user. the user can try two times before the program closes.
The program runs except for the else part in the except . It suppose to print (close program) and quit once the user tried twice to add the input . but instead it shows the following error.
z=0 while (z<2): x=input("Work Hours: ") y= input("Hour Rate :") try: xx=float(x) yy=float(y) break except: if z < 2: print("Try again, Please Write a numeric input") z+=1 else: print("Close program") quit() if xx > 40 : Pay=xx*yy Ovt=(xx-40.0)*(yy*0.5) else: Pay=xx*yy print("Pay:", round(Pay)
Error:Work Hours: dsds6
Hour Rate :dscsd
Try again, Please Write a numeric input
Work Hours: dss
Hour Rate :sd
Try again, Please Write a numeric input
Traceback (most recent call last):
File "C:\Users\maha\Desktop\Full Stack Web developement Courses\University of MICHIGAN\2-Python for Everybody Specialization\1-Programming for Everybody (Getting Started with Python)\Practice Folder\Pay_Rate.py", line 19, in <module>
if xx > 40 :
NameError: name 'xx' is not defined