Last active
April 29, 2024 15:53
-
-
Save kRHYME7/2e45c4df6a5c62330578ea3b8682fe92 to your computer and use it in GitHub Desktop.
# Python Code to evaluate a grade by Kenneth Alampay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#? This one uses for loop to match each value | |
# Define a list of tuples for grade ranges and messages | |
grades = [(0, 74, "Do better next time."), (75, 89, "Good job!"), (90, 100, "Excellent job!")] | |
# Ask for grade input and convert it to float | |
grade = float(input("Enter your grade: ")) | |
# Find and print the corresponding message | |
for min_grade, max_grade, message in grades: | |
if min_grade <= grade <= max_grade: | |
print(message) | |
break | |
else: | |
print("This is an invalid input!") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#? Ask for grade input | |
#? Use float to handle decimals | |
grade = float(input("Enter your grade: ")) | |
# Check the grade and print the corresponding message | |
if grade < 75: | |
print("Do better next time.") | |
elif 75 <= grade < 90: | |
print("Good job!") | |
elif 90 <= grade <= 100: | |
print("Excellent job!") | |
else: | |
print("This is an invalid input!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version 2