๐Ÿ”’ Closed Python code pa help mga boss

Status
Not open for further replies.
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.
 
Status
Not open for further replies.

About this Thread

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

New Topics

Online now

Members online
682
Guests online
14,827
Total visitors
15,509

Forum statistics

Threads
2,362,175
Posts
29,414,631
Members
1,056,865
Latest member
danielban
Back
Top