Chapter 2, An Introduction to Declarations, Assignments and Variables

Program 2-1 , Page number: 20

In [1]:
# An introduction to variable declarations 

number = 7 # no need of declaration of variable. Python is dynamically-typed language
print "There are %d days in a week."%number
There are 7 days in a week.

Program 2-2 , Page number: 21

In [2]:
# A simple program with two declarations

minutes = 60
hours = 24

print "There are %d minutes in an hour."%minutes
print "And %d hours in a day."%hours
There are 60 minutes in an hour.
And 24 hours in a day.

Program 2-4 , Page number: 22

In [3]:
# prints values of two variables

dozens = 17
units = dozens * 12

print "%d units is equivalent to %d dozen."%(units,dozens)
204 units is equivalent to 17 dozen.