Chapter 3 - Variables

example 3.1, page no. 62

In [2]:
testScore = 0 #will declare testScore as an integer

example 3.2, page no. 63

In [3]:
testScore
Out[3]:
0

example 3.3, page no. 65

In [4]:
testScore = 0
print id(testScore)
27819200

example 3.4, page no. 66

In [5]:
import sys

testScore = 0
myGPA = 0.0

print "The address of testScore is: ", id(testScore)
print "The size of testScore is: ", sys.getsizeof(testScore)
print "The address of myGPA is: ", id(myGPA)
print "The size of myGPA is: ", sys.getsizeof(myGPA)
The address of testScore is:  27819200
The size of testScore is:  24
The address of myGPA is:  42871928
The size of myGPA is:  24

example 3.5, page no. 68

In [6]:
testScore = 95;
print "Your test score is: ", testScore
testScore = 75
print "Your test score now is: ", testScore
Your test score is:  95
Your test score now is:  75

example 3.6, page no. 69

In [7]:
testScore = 77.83;
print "The test score is: ", testScore
print "The test score is: ", int(testScore) # explicitly converting to integer
The test score is:  77.83
The test score is:  77

example 3.7 page no. 69

In [8]:
testScore = 32768;
print "Your test score is: ", testScore
Your test score is:  32768

example 3.8 page no. 70

In [9]:
testScore = -32769
print "Your test score is: ", testScore
Your test score is:  -32769

example 3.9, page no. 71

In [ ]:
testScore = int(raw_input())
print "Your test score is: ", testScore

example 3.10, page no. 71

In [11]:
testScore = int(raw_input("Enter your test score: "))
print "Your test score is: ", testScore
Enter your test score: 89
Your test score is:  89

example 3.11, page no. 73

In [13]:
print "Enter your name: ",
myName = raw_input()
print "Enter your weight in pounds: ",
myWeight = raw_input()
print "Enter your height in inches: ",
myHeight = raw_input()
print "Your name score is: ", myName
print "Your weight in pounds is ", myWeight
print "Your height in inches is ", myHeight
Enter your name: Hardik
 Enter your weight in pounds: 90
 Enter your height in inches: 50
 Your name score is:  Hardik
Your weight in pounds is  90
Your height in inches is  50

example 3.12, page no. 74

In [15]:
print "Enter your name: ",
myName = raw_input()
print "Enter your weight in pounds: ",
myWeight = raw_input()
print "Enter your height in inches: ",
myHeight = raw_input()
print "Your name score is: ", myName
print "Your weight in pounds is ", myWeight
print "Your height in inches is ", myHeight
Enter your name: Hardik
 Enter your weight in pounds: 90
 Enter your height in inches: 50
 Your name score is:  Hardik
Your weight in pounds is  90
Your height in inches is  50

example 3.13, page no. 75

In [16]:
print "Enter your name: ",
name = raw_input()
print "Your name is ", name
Enter your name: Hardik
 Your name is  Hardik

example 3.14 page no. 76

In [1]:
testScore = 32769
print "Your test score is: ", testScore
Your test score is:  32769
In [ ]: