lmayo

Exercise 2.4

Dec 28th, 2011
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # Author: Landon Mayo
  3.  
  4. # Exercise 2.4 Assume that we execute the following assignment statements:
  5.  
  6. # width = 17
  7. # height = 12.0
  8.  
  9. '''
  10. For each of the following expressions, write the value of the expression and the type (of the
  11. value of the expression).
  12. '''
  13. # 1. width/2
  14. # 2. width/2.0
  15. # 3. height/3
  16. # 4. 1 + 2 * 5
  17.  
  18. # Use the Python interpreter to check your answers.
  19.  
  20.  
  21. # 1. value=8, type=int
  22. '''
  23. >>> 17/2
  24. 8
  25. >>> type(17/2)
  26. <type 'int'>
  27. >>>
  28. '''
  29.  
  30. # 2. value=8.5, type=float
  31. '''
  32. >>> 17/2.0
  33. 8.5
  34. >>> type(17/2.0)
  35. <type 'float'>
  36. >>>
  37. '''
  38.  
  39. # 3. value=4.0, type=float
  40. '''
  41. >>> 12.0/3
  42. 4.0
  43. >>> type(12.0/3)
  44. <type 'float'>
  45. >>>
  46. '''
  47.  
  48.  
  49. # 4. value=11, type=int
  50. '''
  51. >>> 1 + 2 * 5
  52. 11
  53. >>> type( 1 + 2 * 5 )
  54. <type 'int'>
  55. >>>
  56. '''
Advertisement
Add Comment
Please, Sign In to add comment