File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# bounce.py
22#
33# Exercise 1.5
4+ initHeight = 100
5+ returnBounce = 3 / 5
6+ bounces = 10
7+ for i in range (10 ):
8+ initHeight = round (initHeight * returnBounce , 4 )
9+ print (i + 1 , initHeight )
10+
11+ print ("done" )
Original file line number Diff line number Diff line change 11# mortgage.py
22#
33# Exercise 1.7
4+ principal = 500000.0
5+ rate = 0.05
6+ payment = 2684.11
7+ total_paid = 0.0
8+ month = 0
9+ extra_payment_start_month = 49
10+ extra_payment_end_month = extra_payment_start_month + 4 * 12
11+ extra_payment = 1000
12+
13+ while principal > 0 :
14+ month = month + 1
15+ if month >= extra_payment_start_month and month < extra_payment_end_month :
16+ extraPmt = extra_payment
17+ else :
18+ extraPmt = 0.0
19+ if principal * (1 + rate / 12 ) - payment - extraPmt < 0 :
20+ if principal * (1 + rate / 12 ) - payment < 0 :
21+ payment = principal * (1 + rate / 12 )
22+ extraPmt = 0
23+ else : # ExtraPmt puts it over
24+ extraPmt = principal * (1 + rate / 12 ) - payment
25+ principal = principal * (1 + rate / 12 ) - payment - extraPmt
26+ total_paid = total_paid + payment + extraPmt
27+ print (f'Month: { month } Total Paid: ${ total_paid :0.2f} Remaining: ${ principal :0.2f} ' )
28+
29+ print ('Total Paid' , total_paid )
30+ print ('Total Months' , month )
Original file line number Diff line number Diff line change 11# pcost.py
22#
33# Exercise 1.27
4+ import sys
5+ def portfolio_cost (filename ):
6+ import csv
7+ f = open (filename )
8+ rows = csv .reader (f )
9+ totalCost = 0
10+ header = next (rows )
11+ for row in rows :
12+ try :
13+ rowCost = int (row [1 ]) * float (row [2 ])
14+ totalCost = totalCost + rowCost
15+ except ValueError :
16+ print ('Data error' , row )
17+ return totalCost
18+
19+ if len (sys .argv ) == 2 :
20+ filename = sys .argv [1 ]
21+ else :
22+ filename = 'Data/portfolio.csv'
23+
24+ cost = portfolio_cost (filename )
25+ print ('The total cost is: ' , cost )
Original file line number Diff line number Diff line change 1+ # sears tower problem
2+ # tower 1450 ft
3+ # dollar bill 0.004
4+ towerHtFt = 1450.0
5+ towerHtIn = towerHtFt * 12
6+ print ("Height in In" , towerHtIn )
7+ billHt = .004
8+ pileHt = billHt
9+ billCount = 1
10+ day = 1
11+ while pileHt < towerHtIn :
12+ pileHt = pileHt * 2
13+ day = day + 1
14+ print (day , pileHt )
15+
16+ print ("bills required" , pileHt / .004 )
17+ print ("total days" , day )
Original file line number Diff line number Diff line change 1+ # sears tower problem
2+ # tower 1450 ft
3+ # dollar bill 0.004
4+ towerHtFt = 1450.0
5+ towerHtIn = towerHtFt * 12
6+ print ("Height in In" , towerHtIn )
7+ billHt = .004
8+ pileHt = billHt
9+ billCount = 1
10+ day = 1
11+ while pileHt < towerHtIn :
12+ pileHt = pileHt * 2
13+ day = day + 1
14+ print (day , pileHt )
15+
16+ print ("bills required" , pileHt / .004 )
17+ print ("total days" , day )
You can’t perform that action at this time.
0 commit comments