Advertisement
VergeoPaw

50_cl

Sep 20th, 2021
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. # 1
  2. print("***** 1 *****")
  3. people = [
  4.     {
  5.         "Name" : "Anto",
  6.         "Age" : "15",
  7.         "Hobby" : "Football"
  8.     },
  9.     {
  10.         "Name" : "Budi",
  11.         "Age" : "20",
  12.         "Hobby" : "Coding"
  13.     },
  14.     {
  15.         "Name" : "Charlie",
  16.         "Age" : "12",
  17.         "Hobby" : "Gaming"
  18.     }
  19. ]
  20.  
  21. for person in people :
  22.     print(person["Name"])
  23.     print(f"Age : {person['Age']}")
  24.     print(f"Hobby : {person['Hobby']}")
  25.     print()
  26.  
  27.  
  28. # 2
  29. print("***** 2 *****")
  30. pets = [
  31.     {
  32.         "typeOfPet" : "Dog",
  33.         "ownersName" : "Angelice",
  34.         "breed" : "Chihuahua",
  35.         "color": "Black"
  36.     },
  37.     {
  38.         "typeOfPet" : "Cat",
  39.         "ownersName" : "Broody",
  40.         "breed" : "Anggora",
  41.         "color": "White"
  42.     },
  43.     {
  44.         "typeOfPet" : "Dog",
  45.         "ownersName" : "Charlie",
  46.         "breed" : "Bulldog",
  47.         "color": "Brown"
  48.     },
  49.     {
  50.         "typeOfPet" : "Cat",
  51.         "ownersName" : "Dudes",
  52.         "breed" : "Persian",
  53.         "color": "Gray"
  54.     }
  55. ]
  56.  
  57. for pet in pets :
  58.     for key, val in pet.items() :
  59.         print(f"{key.title()} \t: {val.title()}")
  60.     print()
  61.  
  62. # 3
  63. print("***** 3 *****")
  64. cities = {
  65.     "Jakarta" : {
  66.         "Population" : 10560000,
  67.         "FunFact" : "Memiliki stasiun kereta api terbesar se-ASEAN"
  68.     },
  69.     "Palembang" : {
  70.         "Population" : 1600000,
  71.         "FunFact" : "Merupakan kota tertua di Indonesia"
  72.     }
  73. }
  74. for city in cities :
  75.     print(city)
  76.     for key, val in cities[city].items() :
  77.         print(f"{key} \t: {val}")
  78.     print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement