Advertisement
afrizalwahyuadi66

data_siswa.py

Nov 6th, 2024
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.51 KB | None | 0 0
  1. dict_siswa = {
  2.     "siswa01": {"nama":"Andi","jk":"P","tb":165,"bb":76},
  3.     "siswa02": {"nama":"Faizal","jk":"P","tb":155,"bb":50},
  4.     "siswa03": {"nama":"Andry","jk":"P","tb":177,"bb":45},
  5.     "siswa04": {"nama":"Lina","jk":"W","tb":160,"bb":58},
  6.     "siswa05": {"nama":"Rani","jk":"W","tb":157,"bb":52},
  7.     "siswa06": {"nama":"Randy","jk":"P","tb":166,"bb":89},
  8.     "siswa07": {"nama":"Rika","jk":"W","tb":165,"bb":55},
  9.     "siswa08": {"nama":"Rano","jk":"P","tb":159,"bb":65},
  10.     "siswa09": {"nama":"Fazrul","jk":"P","tb":182,"bb":78},
  11.     "siswa10": {"nama":"Agnia","jk":"W","tb":162,"bb":56}
  12. }
  13.  
  14.  
  15. siswa_w = [siswa["nama"] for siswa in dict_siswa.values() if siswa["jk"] == "W"]
  16. print("Nama - nama siswa dengan jenis kelamin \"W\":")
  17. for i, nama in enumerate(siswa_w, 1):
  18.     print(f"{i}. {nama}")
  19. print(f"Jumlah siswa dengan jenis kelamin \"W\" = {len(siswa_w)}\n")
  20.  
  21.  
  22. siswa_p = [siswa["nama"] for siswa in dict_siswa.values() if siswa["jk"] == "P"]
  23. print("Nama - nama siswa dengan jenis kelamin \"P\":")
  24. for i, nama in enumerate(siswa_p, 1):
  25.     print(f"{i}. {nama}")
  26. print(f"Jumlah siswa dengan jenis kelamin \"P\" = {len(siswa_p)}\n")
  27.  
  28.  
  29. siswa_tb_165 = [(siswa["nama"], siswa["tb"]) for siswa in dict_siswa.values() if siswa["tb"] >= 165]
  30. print("Nama - nama siswa dengan tinggi badan >= 165")
  31. for nama, tb in siswa_tb_165:
  32.     print(f"Nama: {nama}; Tinggi Badan: {tb}")
  33. print()
  34.  
  35.  
  36. siswa_bb_70 = [(siswa["nama"], siswa["bb"]) for siswa in dict_siswa.values() if siswa["bb"] >= 70]
  37. print("Nama - nama siswa dengan berat badan >= 70")
  38. for nama, bb in siswa_bb_70:
  39.     print(f"Nama: {nama}; Berat Badan: {bb}")
  40. print()
  41.  
  42.  
  43. berat_p = [siswa["bb"] for siswa in dict_siswa.values() if siswa["jk"] == "P"]
  44. avg_berat_p = sum(berat_p) / len(berat_p) if berat_p else 0
  45. print(f"Berat rata-rata siswa dengan jenis kelamin \"P\": {avg_berat_p}")
  46.  
  47.  
  48. berat_w = [siswa["bb"] for siswa in dict_siswa.values() if siswa["jk"] == "W"]
  49. avg_berat_w = sum(berat_w) / len(berat_w) if berat_w else 0
  50. print(f"Berat rata-rata siswa dengan jenis kelamin \"W\": {avg_berat_w}\n")
  51.  
  52.  
  53. tinggi_p = [siswa["tb"] for siswa in dict_siswa.values() if siswa["jk"] == "P"]
  54. avg_tinggi_p = sum(tinggi_p) / len(tinggi_p) if tinggi_p else 0
  55. print(f"Tinggi badan rata-rata siswa dengan jenis kelamin \"P\": {avg_tinggi_p}")
  56.  
  57. tinggi_w = [siswa["tb"] for siswa in dict_siswa.values() if siswa["jk"] == "W"]
  58. avg_tinggi_w = sum(tinggi_w) / len(tinggi_w) if tinggi_w else 0
  59. print(f"Tinggi badan rata-rata siswa dengan jenis kelamin \"W\": {avg_tinggi_w}")
  60.  
Tags: program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement