CSC231 multBy3.py Program

From dftwiki3
Jump to: navigation, search

--D. Thiebaut 08:14, 3 October 2012 (EDT)


# multBy3.py
# D. Thiebaut
# A simple program showing how Python deals with
# integer overflow.
# (Python V 2.7)
# To run:
#    python multBy3.py
#

a = 2

for i in range( 70 ):
    print a
    a = a * 3













Output

>>> ================================ RESTART ================================
>>> 
2
6
18
54
162
486
1458
4374
13122
39366
118098
354294
1062882
3188646
9565938
28697814
86093442
258280326
774840978
2324522934
6973568802
20920706406
62762119218
188286357654
564859072962
1694577218886
5083731656658
15251194969974
45753584909922
137260754729766
411782264189298
1235346792567894
3706040377703682
11118121133111046
33354363399333138
100063090197999414
300189270593998242
900567811781994726
2701703435345984178
8105110306037952534
24315330918113857602
72945992754341572806
218837978263024718418
656513934789074155254
1969541804367222465762
5908625413101667397286
17725876239305002191858
53177628717915006575574
159532886153745019726722
478598658461235059180166
1435795975383705177540498
4307387926151115532621494
12922163778453346597864482
38766491335360039793593446
116299474006080119380780338
348898422018240358142341014
1046695266054721074427023042
3140085798164163223281069126
9420257394492489669843207378
28260772183477469009529622134
84782316550432407028588866402
254346949651297221085766599206
763040848953891663257299797618
2289122546861674989771899392854
6867367640585024969315698178562
20602102921755074907947094535686
61806308765265224723841283607058
185418926295795674171523850821174
556256778887387022514571552463522
1668770336662161067543714657390566