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"
- '''
- Exercise 3.3 Write a program to prompt for a score between 0.0 and 1.0. If the score is out of
- range print an error. If the score is between 0.0 and 1.0, print a grade using the following table
- '''
- a=raw_input('Enter score:')
- #program stops when you type finish
- while(a!='finish'):
- if(float(a)>=1.0 or float(a)<=0.0):
- print 'Bad Score'
- if float(a)==0.9:
- print 'A'
- elif float(a)==0.8:
- print 'B'
- elif float(a)==0.7:
- print 'C'
- elif float(a)==0.6:
- print 'D'
- elif float(a)<0.6:
- print 'F'
- a=raw_input('Enter your score:')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement