+ 1
what's wrong with this code?
print ("Program menghitung nilai akhir\n") nama = input ("Masukkan nama : ") tugas = input ("Masukan nilai tugas : ") uts = input ("Masukkan nilai UTS : ") uas = input ("Masukkan nilai UAS : ") print ("\n") na = 0.25 * float (tugas) + 0.35 * float (uts) + 0.40 * float (uas) print ("Nama = ", nama) print ("Nilai akhir = ", na) if na >= 75 : print ("Grade = A") if na >= 60 : print ("Grade = B") if na >= 45 : print ("Grade = C") if na <=45 : print ("Grade = D")
6 Antworten
+ 3
Indentation error. After the first if statement, all the rest are nested under it. Unindent them to match the first one, but leave the print statements as they are. Then make those if statements into elif statements.
+ 2
Sure. Like this:
if na >= 75 :
print ("Grade = A")
elif na >= 60 :
print ("Grade = B")
elif na >= 45 :
print ("Grade = C")
elif na <=45 :
print ("Grade = D")
+ 2
oh, it's work. thank you
+ 1
One more thing... I just noticed also that the last condition should be changed from <=45 to <45, since the condition above it already checked for =45.
Furthermore, since the last condition is meant to account for all the rest of the marks, you may as well make it just plain else.
else :
print ("Grade = D")
+ 1
okay i understand, thx again
0
so i need elif after the first if? can u give me example?