Python Program to Read Marks and Assign a Grade to a Student

Introduction

In this blog post, we will learn how to write a Python program to read marks and assign a grade to a student. We will use the switch case statement to assign grades based on the marks obtained by the student. The grading system will be as follows: A (>=90), B (80-89), C (70-79), D (60-69), E (50-59), F (<50).

Read Marks and Assign a Grade to a Student

Table of Contents

  • Understanding the Grading System
  • Writing the Python Program
  • Testing the Program

Understanding the Grading System

Before we start writing the program, let's understand the grading system. The grading system is based on the marks obtained by the student. The grades are assigned as follows:

  • A (>=90)
  • B (80-89)
  • C (70-79)
  • D (60-69)
  • E (50-59)
  • F (<50)

| Practice Python MCQ at " Python MCQ Programs Interview "

Writing the Python Program

Now let's write the Python program to read marks and assign a grade to a student using the switch case statement. We will use the input() function to accept input from the user for the marks obtained by the student. We will then convert the input string into the float data type using the float() function. We will then use the switch case statement to assign grades based on the marks obtained by the student.

marks = float(input("Enter the marks obtained by the student: "))

grade = None

def switch_case(marks):

    switcher = {

        10: "A",

        9: "A",

        8: "B",

        7: "C",

        6: "D",

        5: "E",

        4: "F",

        3: "F",

        2: "F",

        1: "F",

        0: "F"

    }

    return switcher.get(marks // 10, "Invalid Marks")

grade = switch_case(marks)

print("The grade assigned to the student is:", grade)

Output: 

Enter the marks obtained by the student: 90

The grade assigned to the student is: A

| Learn Python at "  Computer Courses - All in One "

Related FAQ

Q1. What is the grading system used in the Python program to assign grades to students based on their marks?

A1. The grading system used in the Python program to assign grades to students based on their marks is as follows:

A (>=90)

B (80-89)

C (70-79)

D (60-69)

E (50-59)

F (<50)

Q2. How can I write a Python program to calculate the total marks percentage and grade of a student?

A2. To write a Python program to calculate the total marks percentage and grade of a student, you can use the input() function to accept input from the user for the marks obtained by the student. You can then calculate the total marks, average, percentage, and grade of the student using the appropriate formulas. You can also use the switch case statement to assign grades based on the marks obtained by the student.

Q3. How can I assign grades to students based on their marks using the switch case statement in Python?

A3. To assign grades to students based on their marks using the switch case statement in Python, you can use the input() function to accept input from the user for the marks obtained by the student. You can then use the switch case statement to assign grades based on the marks obtained by the student. The switch case statement can be implemented using a dictionary with the keys as the marks range and the values as the corresponding grades.

Q4. How can I create a grade calculator in Python?

A4. To create a grade calculator in Python, you can use the input() function to accept input from the user for the marks obtained by the student. You can then calculate the total marks, average, percentage, and grade of the student using the appropriate formulas. You can also use the switch case statement to assign grades based on the marks obtained by the student. The final test score can be assigned using a formula that takes into account the marks scored in assignments, tests, and lab work.

Q5. How can I display the grades that the students will be receiving in Python?

A5. To display the grades that the students will be receiving in Python, you can use the input() function to accept input from the user for the marks obtained by the student. You can then use the if-else statement or the switch case statement to assign grades based on the marks obtained by the student. You can then print the name of the student along with their grade.

| Practical List - Python [ 4330701 ] [ PRACTICAL EXERCISES ] 

Post a Comment

0 Comments