Advertisement
afrizalwahyuadi66

nested.py

Nov 6th, 2024
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. # nested dictionary
  2. dict_mhs = {
  3.     "mhs01": {"nim": "11990001", "nama": "Hamid", "nilai": 90},
  4.     "mhs02": {"nim": "11990002", "nama": "Hamdun", "nilai": 68},
  5.     "mhs03": {"nim": "11990003", "nama": "Hani", "nilai": 78},
  6.     "mhs04": {"nim": "11990004", "nama": "Heri", "nilai": 50},
  7.     "mhs05": {"nim": "11990005", "nama": "Heru", "nilai": 42}
  8. }
  9.  
  10. # cetak dict mhs
  11. print("Sebelum ditambahkan item nilai huruf")
  12. for mhs in dict_mhs:
  13.     print(dict_mhs[mhs])
  14.  
  15. for mhs in dict_mhs:
  16.     nilai = dict_mhs[mhs]['nilai']
  17.     if nilai > 85:
  18.         huruf = "A"
  19.     elif nilai > 70:
  20.         huruf = "B"
  21.     elif nilai > 65:
  22.         huruf = "C"
  23.     else:
  24.         huruf = "D"
  25.     dict_mhs[mhs]['huruf'] = huruf
  26.  
  27. # cetak dict mhs
  28. print("\nSetelah ditambahkan item nilai huruf")
  29. nomor = 1
  30. for mhs in dict_mhs:
  31.     print(f"Nomor : {nomor}\n"
  32.           f"NIM   : {dict_mhs[mhs]['nim']}\n"
  33.           f"Nama  : {dict_mhs[mhs]['nama']}\n"
  34.           f"Nilai : {dict_mhs[mhs]['nilai']}\n"
  35.           f"Huruf : {dict_mhs[mhs]['huruf']}\n")
  36.     nomor += 1
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement