From 76f3e04b9895cf650d202557c9e042316c4bdc99 Mon Sep 17 00:00:00 2001 From: stepan_svoboda Date: Mon, 8 Jun 2020 14:50:09 +0200 Subject: [PATCH 1/3] 1_5 solution --- Work/bounce.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Work/bounce.py b/Work/bounce.py index 3660ddd82..a1f76ef40 100644 --- a/Work/bounce.py +++ b/Work/bounce.py @@ -1,3 +1,12 @@ # bounce.py # # Exercise 1.5 + +height = 100 +i = 0 + +while i <= 10: + i += 1 + height *= 0.6 + height = round(height, ndigits=4) + print(f'{i} {height}') From 4e3444902018d283adbc7d418ae9adef0c775ba0 Mon Sep 17 00:00:00 2001 From: stepan_svoboda Date: Mon, 8 Jun 2020 15:20:39 +0200 Subject: [PATCH 2/3] 1_10 solution --- Work/mortgage.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Work/mortgage.py b/Work/mortgage.py index d527314e3..9330b7d7a 100644 --- a/Work/mortgage.py +++ b/Work/mortgage.py @@ -1,3 +1,30 @@ # mortgage.py # # Exercise 1.7 + +principal = 500000.0 +rate = 0.05 +payment = 2684.11 +total_paid = 0.0 +month = 0 + +extra_payment = 1000 +extra_payment_start_month = 60 +extra_payment_end_month = 108 + +while principal > 0: + + if principal < payment: + payment = principal * (1+rate/12) + + month += 1 + principal = principal * (1+rate/12) - payment + total_paid = total_paid + payment + + if extra_payment_start_month <= month <= extra_payment_end_month: + principal -= extra_payment + total_paid += extra_payment + + print(month, round(total_paid, 2), round(principal, 2)) + +print('Total paid', total_paid) From 92fe0d8ee1f9a63ef893de4ab569423be54b616b Mon Sep 17 00:00:00 2001 From: stepan_svoboda Date: Mon, 8 Jun 2020 15:39:28 +0200 Subject: [PATCH 3/3] 1_27 solution --- Work/pcost.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Work/pcost.py b/Work/pcost.py index e68aa20b4..a714b1537 100644 --- a/Work/pcost.py +++ b/Work/pcost.py @@ -1,3 +1,13 @@ # pcost.py # # Exercise 1.27 + +overall_cost = 0 + +with open('Data/portfolio.csv', 'rt') as file: + next(file) + for line in file: + _, no_shares, price = line.split(',') + overall_cost += int(no_shares) * float(price) + +print(f'Total cost {overall_cost}')