CSC231 Powers of 2 in Python
Revision as of 10:19, 22 September 2008 by Thiebaut (talk | contribs) (New page: Back to Weekly Schedule ---- =A Python Program that overflows (or not)= <code><pre> # mulby2.py # D. Thiebaut # csc231 # demonstrates how python changes type of # ...)
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