253,334 views
12 votes
12 votes
Python help!

Input a grade level (Freshman, Sophomore, Junior, or Senior) and print the corresponding grade number [9-12]. If it is not one of those grade levels, print Not in High School.
Hint: Since this lesson uses else-if statements, remember to use at least one else-if statement in your answer to receive full credit
Sample Run 1
What year of high school are you in? Freshman
Sample Output 1
You are in grade: 9
Sample Run 2
What year of high school are you in?
Kindergarten
Sample Output 2
Not in High School

User AuxTaco
by
3.0k points

1 Answer

20 votes
20 votes

Answer:

print("What year of high school are you in?")

grade = input()

grade = grade.lower()

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")

Step-by-step explanation:

The first line prints the question. "grade = input()" stores the answer the user will type in the terminal into the variable 'grade'.

grade.lower():

The third line lowercases the entire string ("FreshMan" would turn to "freshman"). Python is case-sensitive.

Then, test the string to see if it matches freshman, sophomore, junior, or senior. If the input string matches print the statement inside the if block. The last statement is the else. It prints if nothing else matches.

User Joey Clover
by
2.5k points