Advertisement
lmayo

exercise2.4 gone too far

Dec 28th, 2011
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.31 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # exercise2.4 gone too far
  3. # Author: Landon Mayo
  4. # I took this exercise a little too far. I couldn't help it.
  5. '''
  6. Exercise 2.4 Assume that we execute the following assignment statements:
  7. width = 17
  8. height = 12.0
  9. For each of the following expressions, write the value of the expression and the type (of the
  10. value of the expression).
  11.  
  12. 1. width/2
  13. 2. width/2.0
  14. 3. height/3
  15. 4. 1 + 2 * 5
  16.  
  17. Use the Python interpreter to check your answers.
  18. '''
  19. # Assignment Statements
  20. width = 17
  21. height = 12.0
  22.  
  23. #define quiz
  24. def quizInstruction():
  25.     print ('For each of the following expressions,\n write the value of the expression and\n the type (of the value of the expression)')
  26.     print ('\n VALUES: \n width = 17\n height = 12.0\n')
  27.  
  28.  
  29.  
  30.  
  31. #Define Expression Executions
  32. execute1 = width/2
  33. execute2 = width/2.0
  34. execute3 = height/3
  35. execute4 = 1 + 2 * 5
  36.  
  37. #Define Expression Strings
  38. express1 = '\n width/2\n'
  39. express2 = 'width/2.0'
  40. express3 = 'height/3'
  41. express4 = '1 + 2 * 5'
  42.  
  43. quizInstruction()
  44.  
  45. # First Qustion:
  46. print express1
  47. quizValue = raw_input("Expected Value: ")
  48. if quizValue == str(8) :
  49.     print 'Correct'
  50. else :
  51.     print 'Wrong'
  52.  
  53. quizType = raw_input("Expected Type: ")
  54. if quizType == 'int' :
  55.     print 'Correct'
  56. else :
  57.     print 'Wrong'
  58.    
  59. # Second Question:
  60. print express2
  61. #Quiz Value for question 2
  62. quizValue = raw_input("Expected Value: ")
  63.  
  64. if quizValue == str(8.5):
  65.     print 'Correct'
  66. else :
  67.     print 'Wrong'
  68.  
  69. # Quiz Type for question 2
  70. quizType = raw_input("Expected Type: ")
  71.  
  72. if quizType == 'float':
  73.     print 'Correct'
  74. else :
  75.     print 'Wrong'
  76.    
  77. ##### Third Question #####
  78.  
  79. print express3
  80.  
  81. #Quiz Value for question 3
  82. quizValue = raw_input("Expected Value: ")
  83. if quizValue == str(4.0):
  84.     print 'Correct'
  85. else :
  86.     print 'Wrong'
  87.  
  88. #Quiz Type for question 3
  89. quizType = raw_input("Expected Type: ")
  90. if quizType == 'float' :
  91.     print 'Correct'
  92. else :
  93.     print 'Wrong'
  94.  
  95. #### Question 4 ####
  96.  
  97. print express4
  98.  
  99. # Quiz Value
  100. quizValue = raw_input("Expected Value: ")
  101. if quizValue == str(11):
  102.     print 'Correct'
  103. else :
  104.     print 'Wrong'
  105. # Quiz Type
  106. quizType = raw_input("Expected Type: ")
  107. if quizType == 'int':
  108.     print 'Correct'
  109. else :
  110.     print 'Wrong'
  111. ####### End Questions #######
  112. print ('Congrats you made it through \n visit http://p2pu.org/en/groups/python-programming-101 to learn python')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement