Advertisement
Guest User

chapter 3 exercises

a guest
Nov 6th, 2013
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. 3.1 pay computation
  2. # -*- coding: iso-8859-15 -*-
  3.  
  4. horas = int(raw_input("Enter hours:"))
  5. precio = float(raw_input("Precio / hora"))
  6.  
  7. if horas > 40:
  8.     extra = horas - 40
  9.     payment = (40 * precio) + ((extra * precio) * 1.5)
  10. else:
  11.     payment = horas * precio
  12.    
  13. print payment
  14.  
  15.  
  16.  
  17. Exercise 3.2 rewrite using try & except
  18. # -*- coding-iso-8859-15 -*-
  19.  
  20. horas = raw_input("Enter hours: ")
  21.  
  22. try:
  23.     horas = int(horas)
  24.     precio = float(raw_input("Precio / hora "))
  25.  
  26.     if horas > 40:
  27.                 extra = horas - 40
  28.                 payment = (40 * precio) + ((extra * precio) * 1.5)
  29.     else:
  30.                 payment = horas * precio
  31.    
  32.     print payment
  33.  
  34.  
  35. except:
  36.     print "no es un numero"
  37.    
  38. Exercise 3.3 scores
  39.  
  40. # -*- coding: iso-8859-15 -*-
  41.  
  42. score= float(raw_input("nota? "))
  43. grade = ""
  44.  
  45. if score > 1.0: #or < 0:
  46.     print "Bad score"
  47. elif score >= 0.9:
  48.         grade = "A"
  49. elif score >= 0.8:
  50.         grade = "B"
  51. elif score >= 0.7:
  52.         grade = "C"
  53. elif score >= 0.6:
  54.         grade = "D"
  55. elif score < 0.6:
  56.         grade = "F"
  57. print grade
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement