#!/usr/bin/env python # coding: utf-8 # In[4]: # Section 4.6 -- input validation loops # How to check (some) inputs # # Do input validation on a simple pay calculator # magic numbers MAX_HOURS=100 # maximum hours acceptable to the program for # one week of work # we will want to exclude non-positive hours worked # and we want to exclude non-positive pay_rate # Ask user for hours worked and pay rate hours_worked=float(input("How many hours did you work?")) pay_rate=float(input("What is your pay rate?")) # while hours_worked>MAX_HOURS or hours_worked<=0 or pay_rate <=0: print("Error with input. Please try again.") hours_worked=float(input("How many hours did you work?")) pay_rate=float(input("What is your pay rate?")) print("Your pay is $",format(hours_worked*pay_rate,'.2f'),sep='') # In[18]: # updated password program -- locks you out after 5 guesses # set the password SECRET_PASSWORD='zugzwang' # how many guesses can be made before being locked out? MAX_GUESSES=5 # allow user to insert inserted_password=input("What is the password?") # count variable for # of failed pw guesses count=0 # validation loop while inserted_password!=SECRET_PASSWORD and count