Make a simple python program that will determine the year level of a student depending on the following inputs:
1 - Freshmen
2 - Sophomore
3- Junior
4- Senior
1 - Freshmen
2 - Sophomore
3- Junior
4- Senior
def get_year_level():
try:
year = int(input("Enter the student's year level: "))
if year == 1:
return "Freshman"
elif year == 2:
return "Sophomore"
elif year == 3:
return "Junior"
elif year == 4:
return "Senior"
else:
return "Invalid year level"
except ValueError:
return "Invalid input"
year_level = get_year_level()
print("Year level:", year_level)
get_year_level()
that prompts the user to enter a year level. The input is then converted to an integer and checked against different conditions using if-elif-else statements. Depending on the value entered, the function returns the corresponding year level or an "Invalid year level" message if the input is not 1, 2, 3, or 4.get_year_level()
function and prints the resulting year level.