Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding workshop 23.9.2021
- from datetime import date
- import math
- start_money = 35000
- # typical yearly interest in math problems = 4-7%
- interest = 7
- # datetime module to calculate amount of days and years between two dates
- save_date = date(2021, 9, 23)
- withdrawal_date = date(2025, 12, 31)
- delta = withdrawal_date - save_date
- days = delta.days
- years = days // 365
- leftover_days = days % 365
- # compound interest formula:
- # A = P*(1+interest)^years
- # A = P* (1+r/n)^nt
- total_money = start_money * math.pow((1 + (interest/100)), years)
- total_money = round(total_money, 2)
- print(total_money)
- # how much we earned?
- new_money = total_money - start_money
- print(f"We earned {new_money} € during {years} time!")
- # the missing days are not taken into account as partial interest
- # you can do that if you wish to calculate this a bit better
- # NEW FILE
- import math
- from datetime import datetime
- coffee_break = datetime(2021, 9, 23, 11, 0, 0)
- evening = datetime(2021, 9, 23, 20, 0, 0)
- duration = evening - coffee_break
- seconds = duration.total_seconds()
- minutes = seconds / 60
- # hours between the two timestamps
- hours = minutes // 60
- hours = int(hours)
- # let's use half life of 4 hours for coffee
- half_life = 8
- # our coffee cup is 300 ml!
- cup = 300
- # half-life calculation
- # y(9) = 1 e(ln(0.5)/6)×9 = 0.35
- logarithm = math.log(0.5) / half_life
- coffee_in_body = cup * math.exp(logarithm * hours)
- coffee_in_body = int(coffee_in_body)
- coffee_mg = 0.4
- print(f"It has been {hours} hours since the coffee cup ({cup} ml)")
- print(f"Half-life was set to {half_life} hours.")
- print(f"Based on the calculation, we still have {coffee_in_body} ml left in our body!")
- # 40mg per 100ml
- coffee_mg_left = coffee_in_body * coffee_mg
- coffee_mg_left = round(coffee_mg_left)
- print(f"This means, we still have about {coffee_mg_left} mg worth of caffeine still in the body.")
Add Comment
Please, Sign In to add comment