
exercise2.4 gone too far
By:
lmayo on
Dec 28th, 2011 | syntax:
Python | size: 2.31 KB | hits: 44 | expires: Never
#!/usr/bin/env python
# exercise2.4 gone too far
# Author: Landon Mayo
# I took this exercise a little too far. I couldn't help it.
'''
Exercise 2.4 Assume that we execute the following assignment statements:
width = 17
height = 12.0
For each of the following expressions, write the value of the expression and the type (of the
value of the expression).
1. width/2
2. width/2.0
3. height/3
4. 1 + 2 * 5
Use the Python interpreter to check your answers.
'''
# Assignment Statements
width = 17
height = 12.0
#define quiz
def quizInstruction():
print ('For each of the following expressions,\n write the value of the expression and\n the type (of the value of the expression)')
print ('\n VALUES: \n width = 17\n height = 12.0\n')
#Define Expression Executions
execute1 = width/2
execute2 = width/2.0
execute3 = height/3
execute4 = 1 + 2 * 5
#Define Expression Strings
express1 = '\n width/2\n'
express2 = 'width/2.0'
express3 = 'height/3'
express4 = '1 + 2 * 5'
quizInstruction()
# First Qustion:
print express1
quizValue = raw_input("Expected Value: ")
if quizValue == str(8) :
print 'Correct'
else :
print 'Wrong'
quizType = raw_input("Expected Type: ")
if quizType == 'int' :
print 'Correct'
else :
print 'Wrong'
# Second Question:
print express2
#Quiz Value for question 2
quizValue = raw_input("Expected Value: ")
if quizValue == str(8.5):
print 'Correct'
else :
print 'Wrong'
# Quiz Type for question 2
quizType = raw_input("Expected Type: ")
if quizType == 'float':
print 'Correct'
else :
print 'Wrong'
##### Third Question #####
print express3
#Quiz Value for question 3
quizValue = raw_input("Expected Value: ")
if quizValue == str(4.0):
print 'Correct'
else :
print 'Wrong'
#Quiz Type for question 3
quizType = raw_input("Expected Type: ")
if quizType == 'float' :
print 'Correct'
else :
print 'Wrong'
#### Question 4 ####
print express4
# Quiz Value
quizValue = raw_input("Expected Value: ")
if quizValue == str(11):
print 'Correct'
else :
print 'Wrong'
# Quiz Type
quizType = raw_input("Expected Type: ")
if quizType == 'int':
print 'Correct'
else :
print 'Wrong'
####### End Questions #######
print ('Congrats you made it through \n visit http://p2pu.org/en/groups/python-programming-101 to learn python')