Sure! Here's a simple Python program that determines the year level of a student based on user input:
Python:
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)
In this program, we define a function 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.
Finally, the program calls the get_year_level() function and prints the resulting year level.