diff --git a/Work/bounce.py b/Work/bounce.py index 3660ddd82..429a9ae4d 100644 --- a/Work/bounce.py +++ b/Work/bounce.py @@ -1,3 +1,10 @@ # bounce.py # # Exercise 1.5 +height = 100 +i=1 +while i < 10: + height = height * 0.6 + i = i+1 + print(i, height) + diff --git a/Work/hello.py b/Work/hello.py new file mode 100644 index 000000000..ad35e5ae3 --- /dev/null +++ b/Work/hello.py @@ -0,0 +1 @@ +print("Hello World") diff --git a/Work/mortgage.py b/Work/mortgage.py index d527314e3..e9d07e237 100644 --- a/Work/mortgage.py +++ b/Work/mortgage.py @@ -1,3 +1,32 @@ # mortgage.py # # Exercise 1.7 + + +principal = 500000.0 +rate = 0.05 +payment = 2684.11 +total_paid = 0.0 +month = 0.0 + +#User-defined extra payment variables +extra_payment_start_month=61 # Extra payments start after 5 years (month 61) +extra_payment_end_month = 108 # Extra payments end after 4 years (month 108) +extra_payment = 1000 # Extra payment amount +while principal > 0: + # Chack if the current month is within the extra payment period + if extra_payment_start_month <= month < extra_payment_end_month: + monthly_payment = extra_payment + payment + else: + monthly_payment = payment + # Apply monthly interest and substract the payment + principal = principal * (1+rate/12) - payment + total_paid += monthly_payment + month +=1 + # Final adjustment if the principal goes negative + if principal < 0: + total_paid = total_paid + principal # Adjust the last payment + principal = 0 # Set principal to 0 to exit the loop + print(f'Month: {month} vs {total_paid}') + + diff --git a/Work/pcost.py b/Work/pcost.py index e68aa20b4..f0821097d 100644 --- a/Work/pcost.py +++ b/Work/pcost.py @@ -1,3 +1,21 @@ # pcost.py # # Exercise 1.27 +import csv +each_share = 0.0 +shares = 0.0 +prices = 0.0 +total_cost = 0 +with open('/Users/doston_ra/practical-python/Work/Data/portfolio.csv', 'rt') as file: + reader = csv.reader(file) + next(reader) + for line in reader: + + shares= float(line[1]) + prices = float(line[2]) + each_share = shares * prices + total_cost += each_share + +print('Total cost is ', total_cost) + + diff --git a/Work/sears.py b/Work/sears.py new file mode 100644 index 000000000..681239f2b --- /dev/null +++ b/Work/sears.py @@ -0,0 +1,15 @@ + +bill_thickness = 0.11 * 0.001 # Meters +sears_height = 442 # height meters +day = 1 +num_bills = 1 + +while bill_thickness * num_bills < sears_height: + print(day, num_bills, num_bills * bill_thickness) + day = day + 1 + num_bills = num_bills * 2 + +print('Number of days', day) +print('Number of bills', num_bills) +print('Final height', num_bills * bill_thickness) +