❓ Help Python code pa help mga boss

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
 
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.
 

About this Thread

  • 1
    Replies
  • 505
    Views
  • 1
    Participants
Last reply from:
Unknown user

Trending Topics

Online now

Members online
1,067
Guests online
1,576
Total visitors
2,643

Forum statistics

Threads
2,315,586
Posts
29,183,130
Members
1,182,640
Latest member
re322
Back
Top