From 39ea40211c54dbbe4e16763368c86186f9f1978c Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Sun, 7 Mar 2021 16:45:40 -0500 Subject: [PATCH 01/30] add hello.py --- Work/hello.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Work/hello.py diff --git a/Work/hello.py b/Work/hello.py new file mode 100644 index 000000000..463f69c06 --- /dev/null +++ b/Work/hello.py @@ -0,0 +1,2 @@ +# hello.py +print("Hello world") From 93b09dd84eb8f60ddeae936d802379bad0373ea0 Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Sun, 7 Mar 2021 16:54:51 -0500 Subject: [PATCH 02/30] add sears.py -> calculate days doubling stack of dollar bills to reach height of Sears Tower --- Work/sears.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Work/sears.py diff --git a/Work/sears.py b/Work/sears.py new file mode 100644 index 000000000..0ceb03c16 --- /dev/null +++ b/Work/sears.py @@ -0,0 +1,16 @@ +# sears.py ==> calculate how long it takes for stack of dollar bills to exceed +# height of Sears Tower in Chicago if doubling the number of bills added each +# day +bill_thickness = 0.11 * 0.001 # Meters (0.11mm) +sears_height = 442 # height of Sears Tower in meters +num_bills = 1 +day = 1 + +while num_bills * bill_thickness < sears_height: + print(day, num_bills, num_bills * bill_thickness) + day += 1 + num_bills *= 2 + +print('Number of days ', day) +print('Number of bills ', num_bills) +print('Final height: ', num_bills * bill_thickness) From 7f8ce940e948cdd327e424d94a3fb107e90622ef Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Sun, 7 Mar 2021 17:15:16 -0500 Subject: [PATCH 03/30] Exercise 1.5 calculate first 10 bounces of ball deteriorating at 3/5 of each bounce --- Work/bounce.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Work/bounce.py b/Work/bounce.py index 3660ddd82..6bb5ca830 100644 --- a/Work/bounce.py +++ b/Work/bounce.py @@ -1,3 +1,7 @@ # bounce.py # # Exercise 1.5 +height = 100 +for i in range(1,11): + height *= 0.6 + print(i, round(height, 4)) From 37f91766d2a189e1bd8fc25b3ef02830d7381fd3 Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Sun, 7 Mar 2021 17:54:57 -0500 Subject: [PATCH 04/30] Exercise 1.7 ==> calculate total cost for 30yr mortgage at 5% annualized interest rate --- Work/mortgage.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Work/mortgage.py b/Work/mortgage.py index d527314e3..d0e60e36d 100644 --- a/Work/mortgage.py +++ b/Work/mortgage.py @@ -1,3 +1,13 @@ # mortgage.py # # Exercise 1.7 +principal = 500000.0 +rate = 0.05 +payment = 2684.11 +total_paid = 0.0 + +while principal > 0: + principal = principal * (1 + rate/12) - payment + total_paid += payment + +print("Total paid: ", round(total_paid, 2)) From fdd7a5f4de24ca4b798394041f8a63bac1f200b1 Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Sun, 7 Mar 2021 18:23:33 -0500 Subject: [PATCH 05/30] Exercise 1.8 ==> make extra $1000 payment for first 12mos, calculate total cost and time to complete loan --- Work/mortgage.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Work/mortgage.py b/Work/mortgage.py index d0e60e36d..0ae1856e6 100644 --- a/Work/mortgage.py +++ b/Work/mortgage.py @@ -5,9 +5,17 @@ rate = 0.05 payment = 2684.11 total_paid = 0.0 +months = 0 +paymentPlus = payment + 1000 +for m in range(1,13): + principal = principal * (1 + rate/12) - paymentPlus + total_paid += paymentPlus + months += 1 while principal > 0: principal = principal * (1 + rate/12) - payment total_paid += payment + months += 1 print("Total paid: ", round(total_paid, 2)) +print("It took " + str(months) + " months to payoff loan") From 37fd0fac1ad38af8c78a9e41147fcccc1025f577 Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Sun, 7 Mar 2021 19:24:32 -0500 Subject: [PATCH 06/30] Exercise 1.9 :: more general case of extra payments for part of payoff period --- Work/mortgage.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Work/mortgage.py b/Work/mortgage.py index 0ae1856e6..eb752eb53 100644 --- a/Work/mortgage.py +++ b/Work/mortgage.py @@ -7,15 +7,20 @@ total_paid = 0.0 months = 0 -paymentPlus = payment + 1000 -for m in range(1,13): - principal = principal * (1 + rate/12) - paymentPlus - total_paid += paymentPlus - months += 1 +extra_payment = 1000 +extra_payment_start_month = 61 +extra_payment_end_month = 108 + while principal > 0: principal = principal * (1 + rate/12) - payment total_paid += payment months += 1 + if months >= extra_payment_start_month and months <= extra_payment_end_month: + principal -= extra_payment + total_paid += extra_payment + print("Month: " + str(months) + " TotalPaid: " + str(round(total_paid,2)) + + " PrincipalRemaining: " + str(round(principal,2))) + print("Total paid: ", round(total_paid, 2)) print("It took " + str(months) + " months to payoff loan") From 9623a5925ad91f67f8eb0637cb46107f7f7c9342 Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Sun, 7 Mar 2021 19:53:58 -0500 Subject: [PATCH 07/30] edit README.md for clarity :^D --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 21efa4540..e6d4d6ae8 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ discussion. ### Q: Are there course videos I can watch? -No. This course is about you writing Python code, not watching someone else. +No. This course is about you writing Python code, not watching someone else write Python code. ### Q: How is this course licensed? From 50d01bcd0d66f836f1ff28881583e12abc4c9896 Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Fri, 12 Mar 2021 18:31:13 -0500 Subject: [PATCH 08/30] Exercise 1.1 --- Work/ex1.1.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Work/ex1.1.py diff --git a/Work/ex1.1.py b/Work/ex1.1.py new file mode 100644 index 000000000..8562df8bf --- /dev/null +++ b/Work/ex1.1.py @@ -0,0 +1,14 @@ +# Lucky Larry bought 75 shares of Google stock at a price of $235.14 per share. Today, shares of Google are priced at $711.25. Using Python’s interactive mode as a calculator, figure out how much profit Larry would make if he sold all of his shares. + +shares = 75 +boughtPrice = 235.14 +todayPrice = 711.25 +profit = (todayPrice * shares) - (boughtPrice * shares) +if (profit > 0): + print(f'If you sold today you would realize a gain of ${profit}') + +if (profit == 0): + print("Well, at least you didn't lose any money") + +if (profit < 0): + print(f'You lost ${abs(profit)} ') From e444812f7be397ab80c2a9bb87a9bd2c8b65862e Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Fri, 12 Mar 2021 18:36:16 -0500 Subject: [PATCH 09/30] .vscode in .gitignore not pushing editor settings --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b6e47617d..551c992a4 100644 --- a/.gitignore +++ b/.gitignore @@ -101,7 +101,7 @@ celerybeat.pid # SageMath parsed files *.sage.py -# Environments +# Environments -- Editors and Python .env .venv env/ @@ -109,6 +109,7 @@ venv/ ENV/ env.bak/ venv.bak/ +.vscode # Spyder project settings .spyderproject From ac95fe365dcec1530d0b08e2fbbeabb4bc866822 Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Thu, 1 Jul 2021 07:31:17 -0400 Subject: [PATCH 10/30] use f strings in print statements --- Work/mortgage.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Work/mortgage.py b/Work/mortgage.py index eb752eb53..6eaf1edc1 100644 --- a/Work/mortgage.py +++ b/Work/mortgage.py @@ -19,8 +19,7 @@ if months >= extra_payment_start_month and months <= extra_payment_end_month: principal -= extra_payment total_paid += extra_payment - print("Month: " + str(months) + " TotalPaid: " + str(round(total_paid,2)) + - " PrincipalRemaining: " + str(round(principal,2))) +print(f"Month: {months:17}\nTotalPaid: {total_paid:19.2f}\nPrincipalRemaining: {principal:6.2f}") -print("Total paid: ", round(total_paid, 2)) -print("It took " + str(months) + " months to payoff loan") +print(f"Total paid: {total_paid:18.2f}") +print(f"It took {months} months to payoff loan") From 26956e9793356f2a8adf7ab0b99708554ae61c23 Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Thu, 1 Jul 2021 09:15:03 -0400 Subject: [PATCH 11/30] Calculate total cost of stock portfolio by pulling in values from csv --- Work/pcost.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Work/pcost.py b/Work/pcost.py index e68aa20b4..13c950f8e 100644 --- a/Work/pcost.py +++ b/Work/pcost.py @@ -1,3 +1,12 @@ # pcost.py # # Exercise 1.27 +totalCost = 0 +with open('Data/portfolio.csv','rt') as f: + headers = next(f).split(',') + for line in f: + row = line.split(',') + nshares = int(row[1]) + price = float(row[2]) + totalCost += nshares * price +print(f'Total cost: {totalCost:.2f}') From 5ec3d5bfbe03350534ad16c00542ff89e7cba83b Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Thu, 1 Jul 2021 09:44:29 -0400 Subject: [PATCH 12/30] add try except clause for missing or bad values in csv --- Work/pcost.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Work/pcost.py b/Work/pcost.py index 13c950f8e..299780abb 100644 --- a/Work/pcost.py +++ b/Work/pcost.py @@ -1,12 +1,18 @@ # pcost.py # # Exercise 1.27 -totalCost = 0 -with open('Data/portfolio.csv','rt') as f: - headers = next(f).split(',') - for line in f: - row = line.split(',') - nshares = int(row[1]) - price = float(row[2]) - totalCost += nshares * price -print(f'Total cost: {totalCost:.2f}') +def portfolioCost(filename): + totalCost = 0 + with open(filename, 'rt') as f: + headers = next(f).split(',') + try: + for line in f: + row = line.split(',') + nshares = int(row[1]) + price = float(row[2]) + totalCost += nshares * price + except ValueError: + print('Missing or Bad value') + next(f) + return totalCost +# print(f'Total cost: {portfolioCost('Data/portfolio.csv'):.2f}') From b59fbd1a557aab5721209f37317f1a796e309eb1 Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Thu, 1 Jul 2021 09:56:02 -0400 Subject: [PATCH 13/30] use csv python library to read the csv file --- Work/pcost.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Work/pcost.py b/Work/pcost.py index 299780abb..d005d4582 100644 --- a/Work/pcost.py +++ b/Work/pcost.py @@ -1,18 +1,19 @@ # pcost.py # # Exercise 1.27 +import csv def portfolioCost(filename): totalCost = 0 - with open(filename, 'rt') as f: - headers = next(f).split(',') + with open(filename) as f: + rows = csv.reader(f) + headers = next(rows) try: - for line in f: - row = line.split(',') + for row in rows: nshares = int(row[1]) price = float(row[2]) totalCost += nshares * price except ValueError: print('Missing or Bad value') - next(f) + next(rows) return totalCost # print(f'Total cost: {portfolioCost('Data/portfolio.csv'):.2f}') From bd30e22fd1c63375c49c517595681b0af224b8cf Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Thu, 1 Jul 2021 10:01:55 -0400 Subject: [PATCH 14/30] read path to csv file from command line --- Work/pcost.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Work/pcost.py b/Work/pcost.py index d005d4582..a73d03594 100644 --- a/Work/pcost.py +++ b/Work/pcost.py @@ -2,6 +2,7 @@ # # Exercise 1.27 import csv +import sys def portfolioCost(filename): totalCost = 0 with open(filename) as f: @@ -17,3 +18,9 @@ def portfolioCost(filename): next(rows) return totalCost # print(f'Total cost: {portfolioCost('Data/portfolio.csv'):.2f}') +if len(sys.argv) == 2: + filename = sys.argv[1] +else: + filename = 'Data/portfolio.csv' +cost = portfolioCost(filename) +print(f'Total cost: {cost}') From 156092ed44de579eb7e1a2d4eb8ca5f121c227e1 Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Fri, 2 Jul 2021 06:02:35 -0400 Subject: [PATCH 15/30] add report.py, reads csv into list of tuples data structure --- Work/report.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Work/report.py b/Work/report.py index 47d5da7b1..acb12f739 100644 --- a/Work/report.py +++ b/Work/report.py @@ -1,3 +1,23 @@ # report.py # # Exercise 2.4 +import csv +import sys + +def read_portfolio(filename): + portfolio = [] + with open(filename) as f: + rows = csv.reader(f) + headers = next(rows) + try: + for row in rows: + holding = (row[0],int(row[1]),float(row[2])) + portfolio.append(holding) + except ValueError: + print('Missing or Bad value') + next(rows) + return portfolio + # if len(sys.argv) == 2: + # filename = sys.argv[1] + # else: + # filename = 'Data/portfolio.csv' From 820d4f90cebafb7d40a38dd8a9cf2b04455410d6 Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Fri, 2 Jul 2021 08:07:21 -0400 Subject: [PATCH 16/30] Compare Cost and Current Value stock portfolio use data in csv, Show P/L --- Work/report.py | 58 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/Work/report.py b/Work/report.py index acb12f739..f941f5d42 100644 --- a/Work/report.py +++ b/Work/report.py @@ -5,19 +5,55 @@ import sys def read_portfolio(filename): + """ + Read a stock portfolio from a csv file into a list of dictionary entries including name, # of shares, and current price + """ portfolio = [] with open(filename) as f: rows = csv.reader(f) headers = next(rows) - try: - for row in rows: - holding = (row[0],int(row[1]),float(row[2])) - portfolio.append(holding) - except ValueError: - print('Missing or Bad value') - next(rows) + for row in rows: + stock = { + 'name' : row[0], + 'shares' : int(row[1]), + 'price' : float(row[2]) + } + portfolio.append(stock) return portfolio - # if len(sys.argv) == 2: - # filename = sys.argv[1] - # else: - # filename = 'Data/portfolio.csv' + +def read_prices(filename): + """ + Read a csv file of price data into a dictionary mapping of names to prices + """ + prices = {} + with open(filename) as f: + rows = csv.reader(f) + for row in rows: + try: + prices[row[0]] = float(row[1]) + except IndexError: + pass + return prices + +# check if the files with price data are cli parameters +# set default test data if not passed to script +if len(sys.argv) == 3: + filename1 = sys.argv[1] + filename1 = sys.argv[2] +else: + filename1 = 'Data/portfolio.csv' + filename2 = 'Data/prices.csv' + +portfolio = read_portfolio(filename1) +prices = read_prices(filename2) + +# print value of portfolio followed by value of price list +totalCost = 0.0 +for s in portfolio: + totalCost += s['shares'] * s['price'] +print(f"Total cost of Portfolio: {totalCost:.2f}") +totalValue = 0.0 +for s in portfolio: + totalValue += s['shares'] * prices[s['name']] +print(f"Current Value of Portfolio: {totalValue:.2f}") +print(f"Gain/Loss: {totalValue - totalCost:.2f}") From 0bcf99d40782bf3a5edc654a38cb389158911dcc Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Mon, 25 Apr 2022 14:49:21 -0400 Subject: [PATCH 17/30] add cities.json sample data in json file --- Work/cities.json | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Work/cities.json diff --git a/Work/cities.json b/Work/cities.json new file mode 100644 index 000000000..987e77be8 --- /dev/null +++ b/Work/cities.json @@ -0,0 +1,21 @@ +[{ + "name": "New York", + "pop": 8550405 + }, + { + "name": "Los Angeles", + "pop": 3971883 + }, + { + "name": "Chicago", + "pop": 2720546 + }, + { + "name": "Houston", + "pop": 2296224 + }, + { + "name": "Philadelphia", + "pop": 1567442 + } +] From 7bc0b5389d507710fe0ee1039fecf7332dbe934e Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Mon, 25 Apr 2022 14:51:32 -0400 Subject: [PATCH 18/30] read from cities.json sample data, throw error msg on error --- Work/file_exercise.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Work/file_exercise.py diff --git a/Work/file_exercise.py b/Work/file_exercise.py new file mode 100644 index 000000000..e803119cc --- /dev/null +++ b/Work/file_exercise.py @@ -0,0 +1,23 @@ +# file_exercise.py + +import json + + +def main(): + with open("cities.json") as cities_file: + try: + cities_data = json.load(cities_file) + + print("Largest cities in the US by population:") + for index, entry in enumerate(cities_data): + print(f"{index + 1}: {entry['name']} - {entry['pop']}") + + except json.decoder.JSONDecodeError as error: + print("Sorry, there was an error decoding that json file:") + print(f"\t {error}") + + print("Closing data files...") + + +if __name__ == "__main__": + main() From 081a171add310351847615337f42dfcecce4ded0 Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Mon, 25 Apr 2022 14:52:58 -0400 Subject: [PATCH 19/30] spacing of comment start; flake8 suggestions; prettify source --- Work/sears.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Work/sears.py b/Work/sears.py index 0ceb03c16..b30574874 100644 --- a/Work/sears.py +++ b/Work/sears.py @@ -1,8 +1,8 @@ # sears.py ==> calculate how long it takes for stack of dollar bills to exceed # height of Sears Tower in Chicago if doubling the number of bills added each # day -bill_thickness = 0.11 * 0.001 # Meters (0.11mm) -sears_height = 442 # height of Sears Tower in meters +bill_thickness = 0.11 * 0.001 # Meters (0.11mm) +sears_height = 442 # height of Sears Tower in meters num_bills = 1 day = 1 From 3f5723b24226c60af95c4bbfa55c258f9f07d8c2 Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Mon, 25 Apr 2022 15:41:04 -0400 Subject: [PATCH 20/30] prettify source using flake8 suggestions --- Work/bounce.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Work/bounce.py b/Work/bounce.py index 6bb5ca830..e12f02b32 100644 --- a/Work/bounce.py +++ b/Work/bounce.py @@ -2,6 +2,6 @@ # # Exercise 1.5 height = 100 -for i in range(1,11): +for i in range(1, 11): height *= 0.6 print(i, round(height, 4)) From 1409d3710bdc6c59b98f2fcec664cdec9ab650c7 Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Mon, 30 May 2022 12:53:35 -0400 Subject: [PATCH 21/30] Start moving Exercises into dirys not just branches --- Work/{ => 1_5}/bounce.py | 0 Work/{ => 1_6}/sears.py | 3 ++- Work/{ => 1_7}/mortgage.py | 0 3 files changed, 2 insertions(+), 1 deletion(-) rename Work/{ => 1_5}/bounce.py (100%) rename Work/{ => 1_6}/sears.py (83%) rename Work/{ => 1_7}/mortgage.py (100%) diff --git a/Work/bounce.py b/Work/1_5/bounce.py similarity index 100% rename from Work/bounce.py rename to Work/1_5/bounce.py diff --git a/Work/sears.py b/Work/1_6/sears.py similarity index 83% rename from Work/sears.py rename to Work/1_6/sears.py index b30574874..561dca19e 100644 --- a/Work/sears.py +++ b/Work/1_6/sears.py @@ -8,9 +8,10 @@ while num_bills * bill_thickness < sears_height: print(day, num_bills, num_bills * bill_thickness) + # day = days + 1 # FIX THIS day += 1 num_bills *= 2 print('Number of days ', day) print('Number of bills ', num_bills) -print('Final height: ', num_bills * bill_thickness) +print(f'Final height {num_bills * bill_thickness} meters') diff --git a/Work/mortgage.py b/Work/1_7/mortgage.py similarity index 100% rename from Work/mortgage.py rename to Work/1_7/mortgage.py From 95656e0d5a85152b254b61a7be0d0740464439be Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Mon, 30 May 2022 13:01:55 -0400 Subject: [PATCH 22/30] Fix Exercise 1.7 --- Work/1_7/mortgage.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Work/1_7/mortgage.py b/Work/1_7/mortgage.py index 6eaf1edc1..987dc1852 100644 --- a/Work/1_7/mortgage.py +++ b/Work/1_7/mortgage.py @@ -5,21 +5,9 @@ rate = 0.05 payment = 2684.11 total_paid = 0.0 -months = 0 - -extra_payment = 1000 -extra_payment_start_month = 61 -extra_payment_end_month = 108 while principal > 0: principal = principal * (1 + rate/12) - payment total_paid += payment - months += 1 - - if months >= extra_payment_start_month and months <= extra_payment_end_month: - principal -= extra_payment - total_paid += extra_payment -print(f"Month: {months:17}\nTotalPaid: {total_paid:19.2f}\nPrincipalRemaining: {principal:6.2f}") print(f"Total paid: {total_paid:18.2f}") -print(f"It took {months} months to payoff loan") From bb243a308311cdff5779d2cb646186dfed545ed0 Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Mon, 30 May 2022 13:06:59 -0400 Subject: [PATCH 23/30] Fix Exercise 1.8 --- Work/1_8/mortgage.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Work/1_8/mortgage.py diff --git a/Work/1_8/mortgage.py b/Work/1_8/mortgage.py new file mode 100644 index 000000000..ec9f866b3 --- /dev/null +++ b/Work/1_8/mortgage.py @@ -0,0 +1,23 @@ +# mortgage.py +# +# Exercise 1.8 +principal = 500000.0 +rate = 0.05 +payment = 2684.11 +total_paid = 0.0 +months = 0 + +extra_payment = 1000 + +while principal > 0: + principal = principal * (1 + rate/12) - payment + total_paid += payment + months += 1 + + if months <= 12: + principal -= extra_payment + total_paid += extra_payment +print(f"Month: {months:17}\nTotalPaid: {total_paid:19.2f}\nPrincipalRemaining: {principal:6.2f}") + +print(f"Total paid: {total_paid:18.2f}") +print(f"It took {months} months to payoff loan") From ca608a1394b6c4b282a5ed6c9d9158459ad5b448 Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Mon, 30 May 2022 13:17:10 -0400 Subject: [PATCH 24/30] Fix up Exercise 1.9 --- Work/1_9/mortgage.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Work/1_9/mortgage.py diff --git a/Work/1_9/mortgage.py b/Work/1_9/mortgage.py new file mode 100644 index 000000000..95fd248a3 --- /dev/null +++ b/Work/1_9/mortgage.py @@ -0,0 +1,25 @@ +# mortgage.py +# +# Exercise 1.9 +principal = 500000.0 +rate = 0.05 +payment = 2684.11 +total_paid = 0.0 +months = 0 + +extra_payment_start_month = 61 +extra_payment_end_month = 108 +extra_payment = 1000 + +while principal > 0: + principal = principal * (1 + rate/12) - payment + total_paid += payment + months += 1 + + if months >= extra_payment_start_month and months <= extra_payment_end_month: + principal -= extra_payment + total_paid += extra_payment +print(f"Month: {months:17}\nTotalPaid: {total_paid:19.2f}\nPrincipal Remaining: {principal:6.2f}") + +print(f"Total paid: {total_paid:18.2f}") +print(f"It took {months} months to payoff loan") From b0e9fa6d6760a2955e080118962342162deaa63c Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Mon, 30 May 2022 13:25:43 -0400 Subject: [PATCH 25/30] Fix up Exercise 1_10 --- Work/1_10/mortgage.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Work/1_10/mortgage.py diff --git a/Work/1_10/mortgage.py b/Work/1_10/mortgage.py new file mode 100644 index 000000000..730fc674d --- /dev/null +++ b/Work/1_10/mortgage.py @@ -0,0 +1,27 @@ +# mortgage.py +# +# Exercise 1.10 +# Change printed reporting to table + +principal = 500000.0 +rate = 0.05 +payment = 2684.11 +total_paid = 0.0 +months = 0 + +extra_payment_start_month = 61 +extra_payment_end_month = 108 +extra_payment = 1000 + +while principal > 0: + principal = principal * (1 + rate/12) - payment + total_paid += payment + months += 1 + print(f"{months} {total_paid:6.2f} {principal:6.2f}") + + if months >= extra_payment_start_month and months <= extra_payment_end_month: + principal -= extra_payment + total_paid += extra_payment + +print(f"Total paid: {total_paid:6.2f}") +print(f"It took {months} months to payoff loan") From 144785882025c38f70cae3408340a89666696e8d Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Mon, 30 May 2022 14:23:40 -0400 Subject: [PATCH 26/30] Exercise 1_11 stop overpaying on mortgage in final month --- Work/1_11/mortgage.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Work/1_11/mortgage.py diff --git a/Work/1_11/mortgage.py b/Work/1_11/mortgage.py new file mode 100644 index 000000000..b21d51fb1 --- /dev/null +++ b/Work/1_11/mortgage.py @@ -0,0 +1,34 @@ +# mortgage.py +# +# Exercise 1.11 +# stop the overpayment in the final month + +principal = 500000.0 +rate = 0.05 +payment = 2684.11 +total_paid = 0.0 +months = 0 + +extra_payment_start_month = 61 +extra_payment_end_month = 108 +extra_payment = 1000 + +while principal > 0: + principal = principal * (1 + rate/12) - payment + total_paid += payment + months += 1 + print(f"{months} {total_paid:6.2f} {principal:6.2f}") + if principal < payment: + months += 1 + total_paid += principal + principal -= principal + print(f"{months} {total_paid:6.2f} {principal:6.2f}") + break + + + if months >= extra_payment_start_month and months <= extra_payment_end_month: + principal -= extra_payment + total_paid += extra_payment + +print(f"Total paid: {total_paid:6.2f}") +print(f"It took {months} months to payoff loan") From 64469c2ac986615bfca050e066f3959c18fbe5dc Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Mon, 30 May 2022 14:32:40 -0400 Subject: [PATCH 27/30] Exercise 1.12 A Mystery --- Work/1_12/exercise.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Work/1_12/exercise.py diff --git a/Work/1_12/exercise.py b/Work/1_12/exercise.py new file mode 100644 index 000000000..99e06179f --- /dev/null +++ b/Work/1_12/exercise.py @@ -0,0 +1,6 @@ +# A Mystery +# converting strings to int and float +int("123") +float("1.23") +# a qouted "False" is a string not a bool that's why +bool("False") # returns True From afe5b34a17efec41d406183a776eef71d3168d83 Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Mon, 30 May 2022 14:52:48 -0400 Subject: [PATCH 28/30] Exercise 1.33 --- Work/{ => 1_33}/pcost.py | 8 ++++++-- Work/ex1.1.py | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) rename Work/{ => 1_33}/pcost.py (91%) diff --git a/Work/pcost.py b/Work/1_33/pcost.py similarity index 91% rename from Work/pcost.py rename to Work/1_33/pcost.py index a73d03594..1b08ab369 100644 --- a/Work/pcost.py +++ b/Work/1_33/pcost.py @@ -1,8 +1,10 @@ # pcost.py # -# Exercise 1.27 +# Exercise 1.33 import csv import sys + + def portfolioCost(filename): totalCost = 0 with open(filename) as f: @@ -18,9 +20,11 @@ def portfolioCost(filename): next(rows) return totalCost # print(f'Total cost: {portfolioCost('Data/portfolio.csv'):.2f}') + + if len(sys.argv) == 2: filename = sys.argv[1] else: - filename = 'Data/portfolio.csv' + filename = '../Data/portfolio.csv' cost = portfolioCost(filename) print(f'Total cost: {cost}') diff --git a/Work/ex1.1.py b/Work/ex1.1.py index 8562df8bf..6df79d414 100644 --- a/Work/ex1.1.py +++ b/Work/ex1.1.py @@ -1,4 +1,7 @@ -# Lucky Larry bought 75 shares of Google stock at a price of $235.14 per share. Today, shares of Google are priced at $711.25. Using Python’s interactive mode as a calculator, figure out how much profit Larry would make if he sold all of his shares. +# Lucky Larry bought 75 shares of Google stock at a price of $235.14 per share. +# Today, shares of Google are priced at $711.25. Using Python’s interactive +# mode as a calculator, figure out how much profit Larry would make if he sold +# all of his shares. shares = 75 boughtPrice = 235.14 From 2815e57be9953d73fd8ff9bb7a42823890773dbc Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Sun, 14 Jan 2024 05:48:39 -0500 Subject: [PATCH 29/30] Add notable directory to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 551c992a4..37a1016c5 100644 --- a/.gitignore +++ b/.gitignore @@ -128,3 +128,6 @@ dmypy.json # Pyre type checker .pyre/ + +# notable +.notable/ From 59484bdf23f51159003a5518bc4bbff2dcf39c6b Mon Sep 17 00:00:00 2001 From: Masked Phrogg <55362644+PhroggDev@users.noreply.github.com> Date: Sun, 14 Jan 2024 06:26:44 -0500 Subject: [PATCH 30/30] move sears.py back into Work diry --- Work/{1_6 => }/sears.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Work/{1_6 => }/sears.py (100%) diff --git a/Work/1_6/sears.py b/Work/sears.py similarity index 100% rename from Work/1_6/sears.py rename to Work/sears.py