tuomasvaltanen

Untitled

Nov 18th, 2021 (edited)
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. # koodipaja 18.11.2021
  2.  
  3. # viikkotehtävässä käytettävät tuotteet
  4. products = ["T1565_2020", "T2432_2019",
  5.             "T8551_2018", "T3345_2019",
  6.             "Y51372_2019", "Y76715_2017",
  7.             "E98144_2018", "T7733_2020",
  8.             "E7614_2021", "E9722_2017",
  9.             "Y89875_2020", "T61287_2021",
  10.             "E9152_2019", "T7749_2021"]
  11.  
  12. # tämä kysytään käyttäjältä
  13. user_year = 2020
  14.  
  15. # samaa split-koodia voi käyttää silmukassakin
  16. for text in products:
  17.     parts = text.split("_")
  18.     code = parts[0]
  19.     year = parts[1]
  20.  
  21.     # jos user_year on sama kuin year => tulostetaan code
  22.     print(f"{code} + {year}")
  23.  
  24.  
  25. # UUSI TIEDOSTO
  26.  
  27. cafe = {
  28.     "name": "Imaginary Cafe Oy",
  29.     "website": "https://edu.frostbit.fi/sites/cafe",
  30.     "categories": [
  31.         "cafe",
  32.         "tea",
  33.         "lunch",
  34.         "breakfast"
  35.     ],
  36.     "location": {
  37.         "city": "Rovaniemi",
  38.         "address": "Testikuja 22",
  39.         "zip_code": "96200"
  40.     }
  41. }
  42.  
  43. location = cafe['location']
  44. city = location['city']
  45. print(city)
  46.  
  47. city = cafe['location']['city']
  48. print(city)
  49.  
  50. # UUSI TIEDOSTO, HUOM TÄMÄ KOODI EI OLE TOIMINTAKUNNOSSA
  51.  
  52. # otetaan nimistä ylimääräiset välilyönnit pois (nimen alusta ja lopusta)
  53. people = [p.strip() for p in people]
  54.  
  55. # people-muuttuja on tässä vaiheessa lista, joka koostuu henkilöiden kokonimistä
  56. #print(people)
  57.  
  58. # tämä funktioon
  59. show_numbered_list("Alkuperäinen järjestys", people)
  60.  
  61. print()
  62. people = sorted(people)
  63.  
  64. # tämä funktioon
  65. for p in people:
  66.     print(p)
Add Comment
Please, Sign In to add comment