Difference between revisions of "CSC231 Powers of 2 in Python"
(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)) |
||
Line 3: | Line 3: | ||
=A Python Program that overflows (or not)= | =A Python Program that overflows (or not)= | ||
− | < | + | <source lang="py"> |
# mulby2.py | # mulby2.py | ||
# D. Thiebaut | # D. Thiebaut | ||
Line 30: | Line 30: | ||
break | break | ||
− | </ | + | </source> |
Revision as of 22:13, 17 January 2010
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