Here's what running my homework programs looks like. For each, I start by running it on something simple where I know what the answer should be, to test what it's doing. In some cases debugging print statements should be used to watch it work, and then commented out for the final version. - Jim ===== chap 2, exercise 1 =============================== [mahoney@hardmaple sep11]$ python chap2ex1.py -- chap2ex1.py ------------------------------------ This is a program to convert Celsius to Fahrenheit. So there. (Are we having fun yet?) --------------------------------------------------- What is the Celsius temperature? 21.0 The temperature is 69.80000000000001 degrees Fahrenheit. [mahoney@hardmaple sep11]$ ===== chap 2, exercise 7 =============================== [mahoney@hardmaple sep11]$ python chap2ex7.py python chap2ex7.py --- chap2ex7.py : compound interest What is the annual percent interest rate? (i.e. 3.0) 3.0 How many periods are there per year? (i.e. 12) 12 What is the initial principal? (i.e. 100.00) 100.0 principal = 100.25 after 1 months principal = 100.500625 after 2 months principal = 100.75187656249999 after 3 months principal = 101.00375625390623 after 4 months principal = 101.25626564454099 after 5 months principal = 101.50940630865233 after 6 months principal = 101.76317982442396 after 7 months principal = 102.01758777398501 after 8 months principal = 102.27263174341996 after 9 months principal = 102.52831332277852 after 10 months principal = 102.78463410608546 after 11 months principal = 103.04159569135066 after 12 months principal = 103.29919968057904 after 13 months principal = 103.55744767978048 after 14 months principal = 103.81634129897992 after 15 months principal = 104.07588215222736 after 16 months principal = 104.33607185760793 after 17 months principal = 104.59691203725195 after 18 months principal = 104.85840431734508 after 19 months principal = 105.12055032813844 after 20 months principal = 105.38335170395878 after 21 months principal = 105.64681008321867 after 22 months principal = 105.9109271084267 after 23 months principal = 106.17570442619777 after 24 months principal = 106.44114368726326 after 25 months principal = 106.70724654648141 after 26 months principal = 106.97401466284761 after 27 months principal = 107.24144969950473 after 28 months principal = 107.50955332375348 after 29 months principal = 107.77832720706286 after 30 months principal = 108.04777302508052 after 31 months principal = 108.31789245764321 after 32 months principal = 108.58868718878732 after 33 months principal = 108.86015890675928 after 34 months principal = 109.13230930402618 after 35 months principal = 109.40514007728623 after 36 months principal = 109.67865292747945 after 37 months principal = 109.95284955979814 after 38 months principal = 110.22773168369763 after 39 months principal = 110.50330101290686 after 40 months principal = 110.77955926543912 after 41 months principal = 111.05650816360271 after 42 months principal = 111.33414943401172 after 43 months principal = 111.61248480759674 after 44 months principal = 111.89151601961574 after 45 months principal = 112.17124480966477 after 46 months principal = 112.45167292168892 after 47 months principal = 112.73280210399314 after 48 months principal = 113.01463410925311 after 49 months principal = 113.29717069452623 after 50 months principal = 113.58041362126254 after 51 months principal = 113.86436465531568 after 52 months principal = 114.14902556695397 after 53 months principal = 114.43439813087134 after 54 months principal = 114.72048412619851 after 55 months principal = 115.007285336514 after 56 months principal = 115.29480354985527 after 57 months principal = 115.5830405587299 after 58 months principal = 115.87199816012672 after 59 months principal = 116.16167815552703 after 60 months principal = 116.45208235091584 after 61 months principal = 116.74321255679313 after 62 months principal = 117.0350705881851 after 63 months principal = 117.32765826465557 after 64 months principal = 117.6209774103172 after 65 months principal = 117.91502985384298 after 66 months principal = 118.20981742847758 after 67 months principal = 118.50534197204877 after 68 months principal = 118.80160532697889 after 69 months principal = 119.09860934029633 after 70 months principal = 119.39635586364707 after 71 months principal = 119.69484675330618 after 72 months principal = 119.99408387018944 after 73 months principal = 120.29406907986491 after 74 months principal = 120.59480425256457 after 75 months principal = 120.89629126319598 after 76 months principal = 121.19853199135396 after 77 months principal = 121.50152832133234 after 78 months principal = 121.80528214213567 after 79 months principal = 122.109795347491 after 80 months principal = 122.41506983585973 after 81 months principal = 122.72110751044937 after 82 months principal = 123.0279102792255 after 83 months principal = 123.33548005492355 after 84 months principal = 123.64381875506085 after 85 months principal = 123.95292830194849 after 86 months principal = 124.26281062270336 after 87 months principal = 124.57346764926011 after 88 months principal = 124.88490131838326 after 89 months principal = 125.19711357167921 after 90 months principal = 125.5101063556084 after 91 months principal = 125.82388162149742 after 92 months principal = 126.13844132555116 after 93 months principal = 126.45378742886503 after 94 months principal = 126.76992189743719 after 95 months principal = 127.08684670218078 after 96 months principal = 127.40456381893623 after 97 months principal = 127.72307522848355 after 98 months principal = 128.04238291655474 after 99 months principal = 128.36248887384613 after 100 months principal = 128.68339509603075 after 101 months principal = 129.00510358377082 after 102 months principal = 129.32761634273024 after 103 months principal = 129.65093538358707 after 104 months principal = 129.97506272204603 after 105 months principal = 130.30000037885114 after 106 months principal = 130.62575037979826 after 107 months principal = 130.95231475574775 after 108 months principal = 131.2796955426371 after 109 months principal = 131.6078947814937 after 110 months principal = 131.93691451844745 after 111 months principal = 132.26675680474355 after 112 months principal = 132.5974236967554 after 113 months principal = 132.9289172559973 after 114 months principal = 133.2612395491373 after 115 months principal = 133.5943926480101 after 116 months principal = 133.92837862963015 after 117 months principal = 134.26319957620422 after 118 months principal = 134.5988575751447 after 119 months principal = 134.93535471908257 after 120 months Done. After 10 years, the principal is 134.93535471908257 ===== chap 2, exercise 10 =============================== [mahoney@hardmaple sep11]$ python chap2ex10.py -- chap2ex10.py -- Convert mm/month to miles/hour. (Wikipedia says hair growth is ~ 125mm/month.) What is the speed in mm/month? (i.e. 125) 125 In miles/hour that is 1.063286215e-07 [mahoney@hardmaple sep11]$ ===== chap 3, exercise 12 =============================== [mahoney@hardmaple sep11]$ python chap3ex12.py -- chap3ex12.py -- Find the sum of the cubes of the first n integers. What is n? 1 The sum of 1**3 + ... + 1 **3 is 1 [mahoney@hardmaple sep11]$ python chap3ex12.py -- chap3ex12.py -- Find the sum of the cubes of the first n integers. What is n? 10 The sum of 1**3 + ... + 10 **3 is 3025 [mahoney@hardmaple sep11]$ ===== chap 3, exercise 14 =============================== [mahoney@hardmaple sep11]$ python chap3ex14.py -- chap3ex14.py -- Find the average of numbers entered by the user. How many numbers will be input? 4 number 1: 1.0 number 2: 2.0 number 3: 3.0 number 4: 4.0 The average is 2.5 [mahoney@hardmaple sep11]$ ===== chap 3, exercise 16 =============================== [mahoney@hardmaple sep11]$ python chap3ex16.py -- chap3ex16.py -- Find the n'th Fibonnaci number. What is n? 10 F[ 10 ] = 55 [mahoney@hardmaple sep11]$ python chap3ex16.py -- chap3ex16.py -- Find the n'th Fibonnaci number. What is n? 1 F[ 1 ] = 1 [mahoney@hardmaple sep11]$ python chap3ex16.py -- chap3ex16.py -- Find the n'th Fibonnaci number. What is n? 2 F[ 2 ] = 1 [mahoney@hardmaple sep11]$ python chap3ex16.py -- chap3ex16.py -- Find the n'th Fibonnaci number. What is n? 3 F[ 3 ] = 2 [mahoney@hardmaple sep11]$ python chap3ex16.py -- chap3ex16.py -- Find the n'th Fibonnaci number. What is n? 1000 F[ 1000 ] = 43466557686937456435688527675040625802564660517371780402481729089536555417949051890403879840079255169295922593080322634775209689623239873322471161642996440906533187938298969649928516003704476137795166849228875 [mahoney@hardmaple sep11]$