Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # nested dictionary
- dict_mhs = {
- "mhs01": {"nim": "11990001", "nama": "Hamid", "nilai": 90},
- "mhs02": {"nim": "11990002", "nama": "Hamdun", "nilai": 68},
- "mhs03": {"nim": "11990003", "nama": "Hani", "nilai": 78},
- "mhs04": {"nim": "11990004", "nama": "Heri", "nilai": 50},
- "mhs05": {"nim": "11990005", "nama": "Heru", "nilai": 42}
- }
- # cetak dict mhs
- print("Sebelum ditambahkan item nilai huruf")
- for mhs in dict_mhs:
- print(dict_mhs[mhs])
- for mhs in dict_mhs:
- nilai = dict_mhs[mhs]['nilai']
- if nilai > 85:
- huruf = "A"
- elif nilai > 70:
- huruf = "B"
- elif nilai > 65:
- huruf = "C"
- else:
- huruf = "D"
- dict_mhs[mhs]['huruf'] = huruf
- # cetak dict mhs
- print("\nSetelah ditambahkan item nilai huruf")
- nomor = 1
- for mhs in dict_mhs:
- print(f"Nomor : {nomor}\n"
- f"NIM : {dict_mhs[mhs]['nim']}\n"
- f"Nama : {dict_mhs[mhs]['nama']}\n"
- f"Nilai : {dict_mhs[mhs]['nilai']}\n"
- f"Huruf : {dict_mhs[mhs]['huruf']}\n")
- nomor += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement