samedi 21 novembre 2020

Can not figure out why my if/else statement doesn`t work like i intend

I am trying to learn simple python. Just testing myself with a simple code before moving on.

My goal is for the program to figure out your average grade, and tell you if it is good or not. Very simple. Problem occurs when typing using the code, the code will under almost every circumstance say your grade is good. If I enter every grade I have as 2, the average grade would clearly be 2. Yet the program says the grade is good.

I initially thought it was a problem with the program reading the inputs as strings. Therefore I tried clarifying that it is supposed to be read as a float. This very well might still be a problem, as I have maybe not clarified it in the right spot of the program. I have tried switching between ">=" and "<=" in my if statement.

Im sure the solution is very simple, but I can not figure it out by myself right now. Kind of expecting myself to facepalm at how easy it is.

Anyway, here is the code:

#Making user type in different grades
math_grade = float(input("Type your math grade here: "))
english_grade = float(input("Type your english grade here: "))
gym_grade = float(input("Type your gym grade here: "))

#Figuring out average grade 
average = math_grade + english_grade + gym_grade / 3

#Attempting to make every grade 3 or under "bad" and everything above "good."
if average <= 3:
    print("Your average grade is bad!")

else:
    print ("Your average grade is good!")

Very little code so should not be hard to copy/paste it and experiment with inputs yourself. Thank you for whatever help I get :)

Aucun commentaire:

Enregistrer un commentaire