Introduction to Python

Activity 1: Grade Calculator

Lesson 6: Conditional Statements

In this activity, we will build a Grade Calculator in Python. The program will ask for a student's score and use conditional statements to determine and display their letter grade.

Illustration of a report card with letter grades A, B, C, D, F written in colorful letters next to score ranges

Grading Criteria

Score RangeGrade
90 and aboveA
80 – 89B
70 – 79C
60 – 69D
Below 60F
Flowchart showing the grade calculation logic with nested if-elif-else decisions checking score ranges from 90 down to 60 and assigning letter grades A through F

Writing the Script

# Grade Calculator def get_grade(score): if score >= 90: return "A" elif score >= 80: return "B" elif score >= 70: return "C" elif score >= 60: return "D" else: return "F" # Main program name = input("Enter student name: ") score = float(input("Enter score: ")) if score < 0 or score > 100: print("Invalid score. Please enter a value between 0 and 100.") else: grade = get_grade(score) print(name + " scored " + str(score) + " and received Grade: " + grade)

Testing the Program

  • Run with name = Ali, score = 92 → Grade: A
  • Run with name = Sara, score = 76 → Grade: C
  • Run with name = Zara, score = 55 → Grade: F
  • Run with score = 105 → Should display invalid score message
Python console showing four test runs of the grade calculator displaying the correct grade for each student name and score input
Save your file with the name Grade Calculator before moving on!

Subscribe to our newsletter.

Get updates to news and events.