#πŸ”’ Can't Run Code Beetwen the Value

13 messages Β· Page 1 of 1 (latest)

peak needle
#

I'm try to create identify, when the value of variable "nilai" beetween 1-20 it's work to run print("Apa-apaan ini?!"), but when the value more than 20, that run a same code, not the next line print code.

nama = input("Nama Siswa : ")
kelas = input("Tingkat Kelas : ")
mapel = input("Mapel Unggulan : ")
print("")

mtk = input("Nilai Matematika : ")
ips = input("Nilai Ilmu Pengetahuan Sosial : ")
ipa = input("Nilai Ilmu Pengetahuan Alam : ")
bindo = input("Nilai Bahasa Indonesia : ")

# Kalkulasi
print(f"\nSemua nilai : {mtk}, {ips}, {ipa}, {bindo} ")
total_nilai = int(mtk) + int(ips) + int(ipa) + int(bindo)
nilai_r2 = total_nilai/4
print("Nilai rata-rata : " + str(nilai_r2))
print("\n[Pesan]")

# This the Problem Code
if nilai_r2 == 0:
    print("Kamu dikeluarkan dari sekolah!")
elif nilai_r2 >= 1 <= 20:
    print("Apa-apaan ini?!")
elif nilai_r2 >= 21 <= 30:
    print("Datang ke ruang BK!")
elif nilai_r2 >= 31 <= 59:
    print("Minta pelajaran tambahan.")
elif nilai_r2 >= 60 <= 70 :
    print("Belajar lebih giat!")
elif nilai_r2 >= 71 <= 80:
    print("Sedikit lagi!")
elif nilai_r2 >= 81 <= 90:
    print("Pertahankan!")
elif nilai_r2 >=91 <= 95:
    print('Luar biasa!')
elif nilai_r2 >=96 <= 99:
    print("Tidak dapat dipercaya!")

w = open(str(nama) + " " + str(kelas) + " " + str(mapel) + ".txt", 'w')
w.write(f"Nama = {nama}\n Kelas = {kelas}\nMapel Unggulan = {mapel}\nNilai Matematika = {mtk}\nNilai IPS = {ips}\nNilai IPA = {ipa}\nNilai Bahasa Indonesia = {bindo}\n\nNilai Total = {total_nilai}\nNilai Rata-Rata = {nilai_r2}\n\n[Pesan]\n")
w.close()```
acoustic lintelBOT
#

@peak needle

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

lunar jolt
#

What you want is

#

if 1 <= value <= 20

#

Put the value in the middle part

peak needle
#

!e

nilai_r2 = 25
if nilai_r2 == 0:
    print("Kamu dikeluarkan dari sekolah!")
elif 1 <= nilai_r2 <= 20:
    print("Apa-apaan ini?!")
elif 21 <=nilai_r2 <= 30:
    print("Datang ke ruang BK!")
elif nilai_r2 >= 31 <= 59:
    print("Minta pelajaran tambahan.")
elif nilai_r2 >= 60 <= 70 :
    print("Belajar lebih giat!")
elif nilai_r2 >= 71 <= 80:
    print("Sedikit lagi!")
elif nilai_r2 >= 81 <= 90:
    print("Pertahankan!")
elif nilai_r2 >=91 <= 95:
    print('Luar biasa!')
elif nilai_r2 >=96 <= 99:
    print("Tidak dapat dipercaya!")```
acoustic lintelBOT
#

@peak needle :x: Your 3.12 eval job has completed with return code 1.

001 | Datang ke ruang BK!
002 | Traceback (most recent call last):
003 |   File "/home/main.py", line 21, in <module>
004 |     w = open(str(nama) + " " + str(kelas) + " " + str(mapel) + ".txt", 'w')
005 |                  ^^^^
006 | NameError: name 'nama' is not defined
peak needle
#

!e

nilai_r2 = 25
if nilai_r2 == 0:
    print("Kamu dikeluarkan dari sekolah!")
elif 1 <= nilai_r2 <= 20:
    print("Apa-apaan ini?!")
elif 21 <=nilai_r2 <= 30:
    print("Datang ke ruang BK!")
elif nilai_r2 >= 31 <= 59:
    print("Minta pelajaran tambahan.")
elif nilai_r2 >= 60 <= 70 :
    print("Belajar lebih giat!")
elif nilai_r2 >= 71 <= 80:
    print("Sedikit lagi!")
elif nilai_r2 >= 81 <= 90:
    print("Pertahankan!")
elif nilai_r2 >=91 <= 95:
    print('Luar biasa!')
elif nilai_r2 >=96 <= 99:
    print("Tidak dapat dipercaya!")```
acoustic lintelBOT
#

@peak needle :white_check_mark: Your 3.12 eval job has completed with return code 0.

Datang ke ruang BK!
peak needle
#

@lunar jolt tysm!

acoustic lintelBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.