Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dict_siswa = {
- "siswa01": {"nama":"Andi","jk":"P","tb":165,"bb":76},
- "siswa02": {"nama":"Faizal","jk":"P","tb":155,"bb":50},
- "siswa03": {"nama":"Andry","jk":"P","tb":177,"bb":45},
- "siswa04": {"nama":"Lina","jk":"W","tb":160,"bb":58},
- "siswa05": {"nama":"Rani","jk":"W","tb":157,"bb":52},
- "siswa06": {"nama":"Randy","jk":"P","tb":166,"bb":89},
- "siswa07": {"nama":"Rika","jk":"W","tb":165,"bb":55},
- "siswa08": {"nama":"Rano","jk":"P","tb":159,"bb":65},
- "siswa09": {"nama":"Fazrul","jk":"P","tb":182,"bb":78},
- "siswa10": {"nama":"Agnia","jk":"W","tb":162,"bb":56}
- }
- siswa_w = [siswa["nama"] for siswa in dict_siswa.values() if siswa["jk"] == "W"]
- print("Nama - nama siswa dengan jenis kelamin \"W\":")
- for i, nama in enumerate(siswa_w, 1):
- print(f"{i}. {nama}")
- print(f"Jumlah siswa dengan jenis kelamin \"W\" = {len(siswa_w)}\n")
- siswa_p = [siswa["nama"] for siswa in dict_siswa.values() if siswa["jk"] == "P"]
- print("Nama - nama siswa dengan jenis kelamin \"P\":")
- for i, nama in enumerate(siswa_p, 1):
- print(f"{i}. {nama}")
- print(f"Jumlah siswa dengan jenis kelamin \"P\" = {len(siswa_p)}\n")
- siswa_tb_165 = [(siswa["nama"], siswa["tb"]) for siswa in dict_siswa.values() if siswa["tb"] >= 165]
- print("Nama - nama siswa dengan tinggi badan >= 165")
- for nama, tb in siswa_tb_165:
- print(f"Nama: {nama}; Tinggi Badan: {tb}")
- print()
- siswa_bb_70 = [(siswa["nama"], siswa["bb"]) for siswa in dict_siswa.values() if siswa["bb"] >= 70]
- print("Nama - nama siswa dengan berat badan >= 70")
- for nama, bb in siswa_bb_70:
- print(f"Nama: {nama}; Berat Badan: {bb}")
- print()
- berat_p = [siswa["bb"] for siswa in dict_siswa.values() if siswa["jk"] == "P"]
- avg_berat_p = sum(berat_p) / len(berat_p) if berat_p else 0
- print(f"Berat rata-rata siswa dengan jenis kelamin \"P\": {avg_berat_p}")
- berat_w = [siswa["bb"] for siswa in dict_siswa.values() if siswa["jk"] == "W"]
- avg_berat_w = sum(berat_w) / len(berat_w) if berat_w else 0
- print(f"Berat rata-rata siswa dengan jenis kelamin \"W\": {avg_berat_w}\n")
- tinggi_p = [siswa["tb"] for siswa in dict_siswa.values() if siswa["jk"] == "P"]
- avg_tinggi_p = sum(tinggi_p) / len(tinggi_p) if tinggi_p else 0
- print(f"Tinggi badan rata-rata siswa dengan jenis kelamin \"P\": {avg_tinggi_p}")
- tinggi_w = [siswa["tb"] for siswa in dict_siswa.values() if siswa["jk"] == "W"]
- avg_tinggi_w = sum(tinggi_w) / len(tinggi_w) if tinggi_w else 0
- print(f"Tinggi badan rata-rata siswa dengan jenis kelamin \"W\": {avg_tinggi_w}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement