diff --git a/Work/bounce.py b/Work/bounce.py index 3660ddd82..18bda0e6d 100644 --- a/Work/bounce.py +++ b/Work/bounce.py @@ -1,3 +1,11 @@ # bounce.py # # Exercise 1.5 +height = 100 # metres +num_bounces = 10 +i = 1 + +while i <= num_bounces: + height = height * 3/5 + print(i, round(height, 4)) + i = i + 1 diff --git a/Work/hello.py b/Work/hello.py new file mode 100644 index 000000000..75d9766db --- /dev/null +++ b/Work/hello.py @@ -0,0 +1 @@ +print('hello world') diff --git a/Work/mortgage.py b/Work/mortgage.py index d527314e3..18da0157a 100644 --- a/Work/mortgage.py +++ b/Work/mortgage.py @@ -1,3 +1,35 @@ # mortgage.py # # Exercise 1.7 + +principal = 500000.0 +rate = 0.05 +payment = 2684.11 +total_paid = 0.0 + +extra_payment_start_month = int(input('extra_payment_start_month: ')) +extra_payment_end_month = int(input('extra_payment_end_month: ')) +extra_payment = int(input('extra_payment: ')) + +current_month = 1 +num_required_months = 0 + +while principal > 0: + if current_month >= extra_payment_start_month and current_month <= extra_payment_end_month: + principal = principal * (1 + rate/12) - payment - extra_payment + total_paid = total_paid + payment + extra_payment + remaining_principal = principal if principal > 0 else 0 + print(f'{current_month}, {total_paid:0.2f}, {remaining_principal:0.2f}') + else: + principal = principal * (1 + rate/12) - payment + total_paid = total_paid + payment + remaining_principal = principal if principal > 0 else 0 + print(f'{current_month}, {total_paid:0.2f}, {remaining_principal:0.2f}') + + current_month = current_month + 1 + num_required_months = num_required_months + 1 + +print(f'Total paid: {total_paid:0.2f}') +print(f'No. of months required to pay the mortgage: {num_required_months}') + + diff --git a/Work/sears.py b/Work/sears.py new file mode 100644 index 000000000..8d834173c --- /dev/null +++ b/Work/sears.py @@ -0,0 +1,16 @@ +bill_thickness = 0.11 * 0.001 # metres (0.11 mm) +sears_height = 442 # height (metres) + +day = 1 +num_bills = 1 +bills_height = 0.11 + +while bills_height < sears_height: + print(day, num_bills, bills_height) + day = day + 1 + num_bills = 2 * num_bills + bills_height = num_bills * bill_thickness + +print('No. of days:', day) +print('No. of bills:', num_bills) +print('Final bills height:', bills_height)