I'm a beginner at coding and use Python. I am trying to use an if else statement but the program only runs on the first statement I give it even if it doesn't meet the conditions to run. For example, if I put an answer other than "UG", "G", or "DL", the program still runs instead of stopping with an error message to the user. I use PyCharm btw.
Here is my project:
studentStatus = str(input("Are you an undergrad (UG), grad (G), or distance learner (DL) student?\n"))
if studentStatus == "UG" or "G" or "DL":
homework = float(input("How many points did you get for your homework?\n"))
homework = (homework / 800) * 100
quiz = float(input("How many points did you get for your quizzes?\n"))
quiz = (quiz / 400) * 100
midterm = float(input("How many points did you get for your midterm exam?\n"))
midterm = (midterm / 150) * 100
final = float(input("How many points did you get for your final exam?\n"))
final = (final / 200) * 100
print(f"Homework: {homework:2.1f}%")
print(f"Quiz: {quiz:2.1f}%")
print(f"Midterm: {midterm:2.1f}%")
print(f"Final: {final:2.1f}%")
else:
print("Error. Student status must be UG, G, or DL.")
I couldn't find an answer on Google as to why my conditional statement isn't working, and I've tried switching the conditional statements so the error message is written first like this:
studentStatus = str(input("Are you an undergrad (UG), grad (G), or distance learner (DL) student?\n"))
if studentStatus != "UG" or "G" or "DL":
print("Error. Student status must be UG, G, or DL.")
else:
homework = float(input("How many points did you get for your homework?\n"))
homework = (homework / 800) * 100
quiz = float(input("How many points did you get for your quizzes?\n"))
quiz = (quiz / 400) * 100
midterm = float(input("How many points did you get for your midterm exam?\n"))
midterm = (midterm / 150) * 100
final = float(input("How many points did you get for your final exam?\n"))
final = (final / 200) * 100
print(f"Homework: {homework:2.1f}%")
print(f"Quiz: {quiz:2.1f}%")
print(f"Midterm: {midterm:2.1f}%")
print(f"Final: {final:2.1f}%")
However, when I do this, the opposite issue happens and only the error message shows up even if I put the correct conditional statement. For example, when I put UG, G, or DL as an input it still read the error. I was expecting the program to skip over the if statement since the input doesn't meet the conditions I gave it.