CSC231 Powers of 2 in Python
Revision as of 08:50, 8 October 2010 by Thiebaut (talk | contribs) (moved CSC231 OverFlow Python Program to CSC231 Python program and infinite loops)
A Python Program that overflows (or not)
# mulby2.py
# D. Thiebaut
# csc231
# demonstrates how python changes type of
# variable as computation progresses. Check
# how an interpreted language would react in this
# situation (mulby2.cpp)
x = 0x1
print "starting value of x = ", x
curType = type( x )
print "type( x ) = ", type( x )
while ( True ):
lastx = x
x = x * 2
print "x = ", x
continue
if type( x )!= type( lastx ):
print "last x = ", lastx
print "type( last x ) = ", type( lastx )
print "x = ", x
print "type( x ) = ", type(x)
break