Advertisement
tuomasvaltanen

Untitled

Oct 7th, 2021 (edited)
1,006
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. # Adobe Connect-koodipaja, 7.10.2021
  2. print("Tervetuloa!")
  3.  
  4. # tämän voisi kysyä käyttäjältä
  5. score = 50
  6.  
  7. # if-elif on kätevä, koska sen avulla vain
  8. # YKSI "if" -lause käynnistyy tarvittaessa!
  9. if 0 < score < 20:
  10.     print("Ensimmäinen if-lause")
  11. elif 20 < score < 40:
  12.     print("Toinen if-lause")
  13. elif 40 < score < 60:
  14.     print("Kolmas if-lause")
  15.  
  16. print("Ohjelma loppui!")
  17.  
  18. # UUSI TIEDOSTO
  19. year = 2018
  20.  
  21. print(f"Vuosiluku sulkeissa ({year})")
  22.  
  23. print("Vuosiluku sulkeissa " + "(" + str(year) + ")")
  24.  
  25. # UUSI TIEDOSTO
  26.  
  27. # jos teksti on sama oikeinpäin ja väärinpäin, kyseessä on palindromi
  28.  
  29. text = "niin niin"
  30. reversed = text[::-1]
  31.  
  32. print(text)
  33. print(reversed)
  34.  
  35. if text == reversed:
  36.     print("Tekstit ovat samoja!")
  37. else:
  38.     # ei ole palindromi
  39.     print("Ei ole ei...")
  40.  
  41. # UUSI TIEDOSTO
  42.  
  43. # booleanit on hyvä alustaa ohjelman alussa
  44. freezing = False
  45. heatwave = False
  46. raining = False
  47. hailstorm = False
  48.  
  49. # nämä käyttäjältä
  50. temperature = 15
  51. humidity = 75
  52.  
  53. # tähän tulee kaikki if-lause -logiikka mikä muuttaa ylläolevia booleaneja!
  54. if temperature > 20:
  55.     heatwave = True
  56.  
  57.  
  58. # lopuksi käytetään booleanien tuloksia hyödyksi!
  59. if freezing:
  60.     print("Kylymä!")
  61.  
  62. if heatwave:
  63.     print("KUUMA!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement