Skip to content

Instantly share code, notes, and snippets.

@kRHYME7
Last active April 29, 2024 15:53
Show Gist options
  • Save kRHYME7/2e45c4df6a5c62330578ea3b8682fe92 to your computer and use it in GitHub Desktop.
Save kRHYME7/2e45c4df6a5c62330578ea3b8682fe92 to your computer and use it in GitHub Desktop.
# Python Code to evaluate a grade by Kenneth Alampay
#? 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!")
#? 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!")
@kRHYME7
Copy link
Author

kRHYME7 commented Apr 29, 2024

Version 2

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment