Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Exercise 3.1 Rewrite your pay computation to give the employee 1.5 times the hourly rate for
- hours worked above 40 hours
- a="Enter Hours:"
- b=raw_input(a)
- c="Enter Rate:"
- d=raw_input(c)
- if int(b)>40:
- print "Pay1",40*float(d)+(int(b)-40)*(float(d)*1.5)
- else:
- print "Pay2",int(b)*float(d)
- Exercise 3.2 Rewrite your pay program using try and except so that your program handles
- non-numeric input gracefully by printing a message and exiting the program. The following
- shows two executions of the program:
- a="Enter Hours:"
- try:
- b=raw_input(a)
- int(b)
- except:
- print "Error, please enter a numeric input"
- c="Enter Rate:"
- try:
- d=raw_input(c)
- float(d)
- if int(b)>40:
- print "Pay1",40*float(d)+(int(b)-40)*(float(d)*1.5)
- else:
- print "Pay2",int(b)*float(d)
- except:
- print "Error,please enter a numeric input"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement