 # Untitled

Sep 23rd, 2021 (edited)
297
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # coding workshop 23.9.2021
2.
3. from datetime import date
4. import math
5.
6. start_money = 35000
7.
8. # typical yearly interest in math problems = 4-7%
9. interest = 7
10.
11. # datetime module to calculate amount of days and years between two dates
12. save_date = date(2021, 9, 23)
13. withdrawal_date = date(2025, 12, 31)
14.
15. delta = withdrawal_date - save_date
16. days = delta.days
17. years = days // 365
18. leftover_days = days % 365
19.
20. # compound interest formula:
21. # A = P*(1+interest)^years
22. # A = P* (1+r/n)^nt
23. total_money = start_money * math.pow((1 + (interest/100)), years)
24. total_money = round(total_money, 2)
25. print(total_money)
26.
27. # how much we earned?
28. new_money = total_money - start_money
29. print(f"We earned {new_money} € during {years} time!")
30.
31. # the missing days are not taken into account as partial interest
32. # you can do that if you wish to calculate this a bit better
33.
34. # NEW FILE
35.
36. import math
37. from datetime import datetime
38.
39. coffee_break = datetime(2021, 9, 23, 11, 0, 0)
40. evening = datetime(2021, 9, 23, 20, 0, 0)
41.
42. duration = evening - coffee_break
43. seconds = duration.total_seconds()
44.
45. minutes = seconds / 60
46.
47. # hours between the two timestamps
48. hours = minutes // 60
49. hours = int(hours)
50.
51. # let's use half life of 4 hours for coffee
52. half_life = 8
53.
54. # our coffee cup is 300 ml!
55. cup = 300
56.
57. # half-life calculation
58. # y(9) = 1 e(ln(0.5)/6)×9 = 0.35
59. logarithm = math.log(0.5) / half_life
60. coffee_in_body = cup * math.exp(logarithm * hours)
61. coffee_in_body = int(coffee_in_body)
62.
63. coffee_mg = 0.4
64.
65. print(f"It has been {hours} hours since the coffee cup ({cup} ml)")
66. print(f"Half-life was set to {half_life} hours.")
67. print(f"Based on the calculation, we still have {coffee_in_body} ml left in our body!")
68.
69. # 40mg per 100ml
70. coffee_mg_left = coffee_in_body * coffee_mg
71. coffee_mg_left = round(coffee_mg_left)
72. print(f"This means, we still have about {coffee_mg_left} mg worth of caffeine still in the body.")
73.
RAW Paste Data