'''
example 6.1 page no :56
'''
def countdown (n):
while (n > 0):
print n
n = n-1
print "Blastoff!"
return 0
countdown(5)
'''
example 6.2 page no :57
'''
def sequence (n):
while (n != 1):
print n
if (n%2 == 0):
n = n / 2
else:
n = n*3 + 1
sequence(10)
'''
example 6.3 page no :58
'''
import math
x = 1.0
while (x < 10.0):
print x , "\t" , math.log(x)
x = x + 1.0
'''
example 6.4 page no :59
'''
import math
x = 1.0
while (x < 10.0):
print x , "\t" , math.log(x) / math.log(2.0)
x = x + 1.0
'''
example 6.5 page no :59
'''
import math
x = 1.0;
while (x < 100.0):
print x , "\t" , math.log(x) / math.log(2.0)
x = x * 2.0
'''
example 6.6 page no: 60
'''
i = 1;
while (i <= 6):
print 2*i ,
i = i + 1;
'''
example 6.7 page no:60
'''
def printMultiples (n):
i = 1
while (i <= 6):
print n*i,
i = i + 1;
printMultiples(3)
'''
example 6.8 page no:61
'''
def printMultiples (n):
i = 1
while (i <= 6):
print n*i,
i = i + 1;
print ''
i = 1;
while (i <= 6):
printMultiples (i);
i = i + 1;
'''
example 6.9 page no: 62
'''
def printMultiples (n):
i = 1
while (i <= 6):
print n*i,
i = i + 1;
print ''
def printMultTable ():
i = 1;
while (i <= 6):
printMultiples (i)
i = i + 1
printMultTable()
'''
example 6.10 page no :63
'''
def printMultiples (n):
i = 1
while (i <= 6):
print n*i,
i = i + 1;
print ''
def printMultTable (high):
i = 1;
while (i <= high):
printMultiples (i);
i = i + 1;
printMultTable(4)
'''
example 6.11 page no :64
'''
def printMultiples(n,high):
i = 1;
while (i <= high):
print n*i ,
i = i + 1;
print ''
def printMultTable (high):
i = 1;
while (i <= high):
printMultiples (i, high)
i = i + 1;
printMultTable(5)