Advertisement
tuomasvaltanen

Untitled

Sep 7th, 2023 (edited)
976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.22 KB | None | 0 0
  1. # Koodipaja, 7.9.2023
  2. print("Tervetuloa!")
  3.  
  4. # viikkotehtävä 2-3
  5. salary = 2700
  6. tax = 24
  7.  
  8. # muutetaan kokonaislukuveroprosentti desimaaliksi => 24 / 100 = 0.24
  9. tax = tax / 100
  10. print(tax)
  11.  
  12. # tämän jälkeen verot saadaan kertomalla salary -muuttuja tax-muuttujalla
  13. # ja käteenjäävä osuus kun vähentää koko palkasta verojen määrän
  14.  
  15. # UUSI TIEDOSTO
  16.  
  17. import math
  18. from datetime import date
  19.  
  20. # korkoa korolle -laskuri
  21.  
  22. # esim: https://raha.fi/korkoa-korolle-laskuri/
  23. # kaava: S × (1+r/100)^t
  24. # esimerkki: 7 000 × (1+7/100)^10 = 13 770,06
  25.  
  26. # alkupääoma ja korkoprosentti
  27. start_money = 20000
  28. profit = 7
  29.  
  30. # rahan tallennuspäivä ja päivä, jolloin rahat nostetaan pois
  31. save_date = date(2023, 9, 7)
  32. withdrawal = date(2033, 12, 31)
  33.  
  34. # kuinka paljon vuosia tällä aikavälillä
  35. delta = withdrawal - save_date
  36. days = delta.days
  37. years = days // 365
  38. print(years)
  39.  
  40. # kaava: S × (1+r/100)^t
  41. total_money = start_money * math.pow(1 + profit / 100, years)
  42. total_money = round(total_money, 2)
  43. print(total_money)
  44.  
  45. # lasketaan kuinka paljon uutta rahaa tienattiin säästämisellä
  46. new_money = total_money - start_money
  47. new_money = round(new_money, 2)
  48.  
  49. print(f"Voittoa tuli: {new_money} €")
  50.  
  51. # UUSI TIEDOSTO
  52.  
  53. import math
  54. from datetime import datetime
  55.  
  56. # kahvin puoliintumisaika -laskuri
  57. # lähde: https://www.mathsisfun.com/algebra/exponential-growth.html
  58. # ks. kohta Half Life (kahviesimerkki)
  59.  
  60. # 1 = kahvin määrä, esim 1 kuppi
  61. # kaava: y(9) = 1 e ^ ((ln(0.5)/6)×9) = 0.35
  62. # kaava = cup * exp^((ln(0.5)/half_life) * hours)
  63.  
  64. # 1 kuppi = oletetaan että 300ml
  65. cup = 300
  66.  
  67. # kofeiinin määrä puolittuu 3–6 tunnissa
  68. half_life = 4
  69.  
  70. then = datetime(2023, 9, 7, 11, 0, 0)
  71. now = datetime(2023, 9, 7, 20, 0, 0)
  72.  
  73. duration = now - then
  74. seconds = duration.total_seconds()
  75.  
  76. # sekunnit minuuteiksi ja sitten tunneiksi
  77. minutes = seconds / 60
  78.  
  79. # / = jakolasku, ja // jakolasku, mutta desimaalit jätetään pois
  80. hours = minutes // 60
  81. print(hours)
  82.  
  83. # kaava = cup * exp^((ln(0.5)/half_life) * hours)
  84. # math.log Pythonissa = ln()
  85. logarithm = math.log(0.5) / half_life
  86. coffee_left = cup * math.exp(logarithm * hours)
  87. coffee_left = int(coffee_left)
  88.  
  89. print(f"Kahvia jäljellä: {coffee_left} ml")
  90.  
  91.  
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement