288,380 views
32 votes
32 votes
3.5 code practice

grade = str(input("What year of high school are you in?: "))

if ("grade ==Freshman"):

print("You are in grade: 9")

elif ("grade == Sophomore"):

print("You are in grade: 10")

elif ("grade == Junior"):

print("You are in grade: 11")

elif ("grade == Senior"):

print("You are in grade: 12")

else:

print("Not in High School")

It keeps printing your are in grade 9. Why?

User Azamat Mahkamov
by
2.5k points

1 Answer

20 votes
20 votes

The fixed code is shown below. input() function already returns string that's why you don't have to convert string again. Also the syntax in if-else scope is wrong.

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

if(grade.lower()=="freshman"):

print("You are in Grade 9.")

elif(grade.lower()=="sophomore"):

print("You are in Grade 10.")

elif(grade.lower()=="junior"):

print("You are in Grade 11.")

elif(grade.lower()=="senior"):

print("You are in Grade 12.")

else:

print("Wrong input!")

User Zsolt Boldizsar
by
2.6k points