69,594 views
29 votes
29 votes
This code is giving no error but is not printing my "goal." Which is to print a year of highschool when a number is input. Instead the code is only printing "Not in High School" every time, every number. Can someone please explain to me what I did wrong?

grade_number = input("What year of high school are you in? ")


if grade_number == 9:

print("Freshman")


elif grade_number == 10:

print("Sophomore")


elif grade_number == 11:

print("Junior")


elif grade_number == 12:

print("Senior")


else:

print("Not in High School")

User Frogmanx
by
2.8k points

1 Answer

14 votes
14 votes

Answer:

You must convert your input to an integer before the if statements.

Step-by-step explanation:

input() returns a string, which should be converted to your desired type, OR you should compare against string literals.

See below for working code.

This code is giving no error but is not printing my "goal." Which is to-example-1
User Amphibient
by
2.7k points