What's new

Help Pa help po python code

Phc - Jemz

Forum Guru
Elite
P help po ako mga idol, dko papo alam kung paano po ito i code,

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
 
Solution
def determine_year_level():
year_levels = {
1: "Freshmen",
2: "Sophomore",
3: "Junior",
4: "Senior"
}

year_input = input("Enter the number representing your year (1-Freshmen, 2-Sophomore, 3-Junior, 4-Senior): ")

try:
year_input = int(year_input)
if year_input in year_levels:
print(f"You are a {year_levels[year_input]}!")
else:
print("Invalid input. Please enter a number from 1 to 4.")
except ValueError:
print("Invalid input. Please enter a number.")

determine_year_level()

1699937690704.png


nawawala indention paps. ayusin mo lang

You do not have permission to view the full content of this post. Log in or register now.
Sure! I can help you with that. Here's a simple Python program that determines the year level of a student based on user input:

Python:
def determine_year_level():
    try:
        # Prompt the user to enter a number from 1 to 4
        grade = int(input("Enter the grade (1-4): "))

        # Determine the year level based on the input
        if grade == 1:
            year_level = "Freshmen"
        elif grade == 2:
            year_level = "Sophomore"
        elif grade == 3:
            year_level = "Junior"
        elif grade == 4:
            year_level = "Senior"
        else:
            year_level = "Invalid input"

        # Print the year level
        print("Year level:", year_level)

    except ValueError:
        print("Invalid input. Please enter a number.")

# Call the function to execute the program
determine_year_level()

In this program, we define a function called determine_year_level that prompts the user to enter a grade as an input. It then uses conditional statements (if, elif, else) to determine the corresponding year level based on the input. Finally, it prints the determined year level.

Note: The program will handle invalid inputs by displaying an error message when the user enters a non-numeric value.

I hope this helps! Let me know if you have any further questions.
 
def determine_year_level():
year_levels = {
1: "Freshmen",
2: "Sophomore",
3: "Junior",
4: "Senior"
}

year_input = input("Enter the number representing your year (1-Freshmen, 2-Sophomore, 3-Junior, 4-Senior): ")

try:
year_input = int(year_input)
if year_input in year_levels:
print(f"You are a {year_levels[year_input]}!")
else:
print("Invalid input. Please enter a number from 1 to 4.")
except ValueError:
print("Invalid input. Please enter a number.")

determine_year_level()

1699937690704.png


nawawala indention paps. ayusin mo lang

You do not have permission to view the full content of this post. Log in or register now.
 

Attachments

Solution
def determine_year_level():
year_levels = {
1: "Freshmen",
2: "Sophomore",
3: "Junior",
4: "Senior"
}

year_input = input("Enter the number representing your year (1-Freshmen, 2-Sophomore, 3-Junior, 4-Senior): ")

try:
year_input = int(year_input)
if year_input in year_levels:
print(f"You are a {year_levels[year_input]}!")
else:
print("Invalid input. Please enter a number from 1 to 4.")
except ValueError:
print("Invalid input. Please enter a number.")

determine_year_level()

View attachment 2815075

nawawala indention paps. ayusin mo lang

You do not have permission to view the full content of this post. Log in or register now.
Thanks idol ♥️ laking tulong po ito sakin♥️
 
def determine_year_level():
year_levels = {
1: "Freshmen",
2: "Sophomore",
3: "Junior",
4: "Senior"
}

year_input = input("Enter the number representing your year (1-Freshmen, 2-Sophomore, 3-Junior, 4-Senior): ")

try:
year_input = int(year_input)
if year_input in year_levels:
print(f"You are a {year_levels[year_input]}!")
else:
print("Invalid input. Please enter a number from 1 to 4.")
except ValueError:
print("Invalid input. Please enter a number.")

determine_year_level()

View attachment 2815075

nawawala indention paps. ayusin mo lang

You do not have permission to view the full content of this post. Log in or register now.
Ito paps nag expire na kasi yung link paps
 

Similar threads

Back
Top