Advertisement
Guest User

Untitled

a guest
Jul 10th, 2012
1,742
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. '''
  2. Exercise 3.1 Rewrite your pay computation to give the employee 1.5 times the hourly rate for
  3. hours worked above 40 hours.
  4. '''
  5. a="Enter Hours:"
  6. b=raw_input(a)
  7. c="Enter Rate:"
  8. d=raw_input(c)
  9. if int(b)>40:
  10.     print "Pay1",40*float(d)+(int(b)-40)*(float(d)*1.5)
  11. else:
  12.     print "Pay2",int(b)*float(d)
  13.  
  14. '''
  15. Exercise 3.2 Rewrite your pay program using try and except so that your program handles
  16. non-numeric input gracefully by printing a message and exiting the program. The following
  17. shows two executions of the program:
  18. '''
  19. a="Enter Hours:"
  20. try:
  21.     b=raw_input(a)
  22.     int(b)
  23. except:
  24.     print "Error, please enter a numeric input"
  25. c="Enter Rate:"
  26. try:
  27.     d=raw_input(c)
  28.     float(d)
  29.     if int(b)>40:
  30.             print "Pay1",40*float(d)+(int(b)-40)*(float(d)*1.5)
  31.     else:
  32.             print "Pay2",int(b)*float(d)
  33. except:
  34.     print "Error,please enter a numeric input"
  35. '''
  36. Exercise 3.3 Write a program to prompt for a score between 0.0 and 1.0. If the score is out of
  37. range print an error. If the score is between 0.0 and 1.0, print a grade using the following table
  38. '''
  39. a=raw_input('Enter score:')
  40. #program stops when you type finish
  41. while(a!='finish'):
  42.     if(float(a)>=1.0 or float(a)<=0.0):
  43.         print 'Bad Score'
  44.     if float(a)==0.9:
  45.         print 'A'
  46.     elif float(a)==0.8:
  47.         print 'B'
  48.     elif float(a)==0.7:
  49.         print 'C'
  50.     elif float(a)==0.6:
  51.         print 'D'
  52.     elif float(a)<0.6:
  53.         print 'F'
  54.     a=raw_input('Enter your score:')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement