Featured Post

BUILD A TODO LIST IN PYTHON

Image
Build a TODO List in Python Overview The objective is to build a todo list to which we can add items, remove the added items, edit the items and even if required, delete out the entire list itself. We will learn here step by step, how to build the todo list with the above  CRUD (Create, Remove, Update/edit, and Delete ) features.  This is a CRUD list  app  that we are building as we can Create, Remove, Update items in the list and Delete the entire list itself. We will be using Python3 to build this Project. Importing os and time We import time to let the screen pause for a while before clearing  and we import os to clear the screen . Initializing the list We initialize the todo list with an empty list as there are not items added yet to the list and this is represented in the code aby using an empty square braces   toDoList = [] Defining the print list  The def keyword is used to define a function in python. In the below code, we define the function called printList(). When we define

Build a Simple Exam Grade Calculator in Python

 Build a Simple Exam Grade Calculator in Python





INTRODUCTION
This blog tutorial will teach you how to build a simple examination grade calculator using Python, in an easy to understand manner with full source code and in depth code explanation with detailed explanation so that you will also understand the main concepts of Python that are applied here to build this app. This Python tutorial is for absolute beginners who are learning Python and if you are in an advanced or intermediate phase of  doing Python, you may find it boring to learn this project!

CORE CONCEPTS OF THE PROJECT
Here, you are going to learn the steps involved in building an exam grade calculator app using Python and the main concepts of this project is having the following information, that is, what is the name of the examination or subject exam, what is the score of the candidate, what is the full score or total marks expected for the respective subject or examination and then, based on the exam score of the candidate, you need to be able to calculate the percentage score of the exam for that candidate and also the grade scored by him or her for that exam. 

PYTHON TOPICS YOU WILL LEARN HERE
You will learn how to create variables in Python, and you will also learn how to use the  following built-in functions, namely, print, input function, round function , float function , round function and int function while doing these calculation for this project. You will also learn how to use the if-elif-else conditional loop while building this project.

Let's understand the print() function
The print() function is an inbuilt python function that is used to implement the print statement or rather this function will print out the statement that you have written as a string within the print() function as a parameter within the parenthesis of the print() function. Without the print() function you will not be able to print out the output of any code on the computer screen. In the code below, you can see that the code starts with the print function where you write the code as 
print("Exam Grade Calculator") and this will execute the statement Exam Grade Calculator on the screen so that you know that this project that you are going to do is about learning how to build an Exam Grade Calculator because, this statement is going to show up as a title in the first line.

Let's understand the input() function
The input() function is another inbuild python function that is used to create variables that store values or data based on what is received as input from the users who are using the computer keyboard to key in the data to the computer. In the code below, you can see that the variable that is created by the name of maxScore is using the input function to get the data input from the user. The other variable that is being created is yourScore.
   maxScore = int(input("Maximum Possible Score: "))

The other variable that is being created is yourScore.
   yourScore = int(input("Your Score: "))

Let's understand the int() function
The int function is also another in built python function that is used in order to convert any number or decimals to an integer. In the below case we use int function since it is understood that examination marks is supposed to be in integers and not decimals. So even if the user does not give a whole number as an input, the output will show you a number that is a whole number or an integer.

Let's understand the float() function
The float() function is an in-built function in python and is used to convert an integer or real number into a floating-point number, that is, a decimal number or a fractional number. So, if you use the float function , for example, float(2) will give the output of 2.0 so, what it did is converted the integer 2 to  decimal number 2.0.

Let's understand the round() function
The round() function is another in-built function in python that is used to round off decimal numbers to a specific number of decimal point numbers. For example, if we consider a decimal number such as 2.67895 that has 5 decimal points and if we want to reduce it to two decimal points then I use the round() function, hence round(2.678952) where the second parameter is the number of digits that you want to round it off to, will yield a result of 2.68 as the round function helped this decimal number to round off the decimal number to two positions, as you can see that there are six digits after the decimal point and the round function reduced the six digits to two digits after the decimal.

Let's understand the if-elif -else loop
The if-elif loop in  21python is used to make conditional statements and yield results based on the different conditions. For example consider a loop such as follows and this is usually used in conditions where there are three or more conditional situatioins such as follows:
if  x < 0 :
  print("x is a  negative number")
elif x == 0:
  print("x is zero")
else:
  print("x is a positive number")

In the above example, for the above if-elif-else loop, what it means is that for the first condition if the number x is less than 0, then, we are asked to print out that x is a negative number and in a second condition which is represented by elif, had the number x been equal to 0, then we print out that x has a value of zero and in the third condition, represented by else, we print out that x is a positive number, because, we have already exhausted two conditions, namely, x is less than zero, whereby x is a negative number and if x is equal to zero, than x has a value of zero , so, the only condition left is that x is more than zero, and if it is more than zero, then, obviously, it is a positive number, so, we show this last condition by write else:  and then we print out the the last possibility for the value of x as shown above.

BUILDING THE APP
The basic code and concepts that are to be used in building this app have already been explained in the above paragraphs, now, we start explaining, step-by-step, the process of building this app.

We use the print() function to print out the title of the app by wrting  print("Exam Grade Calculator")
   print("Exam Grade Calculator")


CREATING VARIABLES USING THE INT() FUNCTION
Next step, we create a variable and name it examName and this is to name the exam for which we are calculating the grades. Since this is a user based variable, in order to get values of the exam names from the user or candidates, we use the input() function and store the values of the exam names that we get as input that are keyed in by the user into the computer and store these values of exam names in the variable examNames. So, how do we write the code for this ? 
   examName = input("What is the name of the exam?: ")

Next, we create another variable called maxScore and also get the values for this variable by using the input() function whereby asking the users to input the maximum possible score for this exam by keying down the values that can be stored in this variable for doing our calculation later on. This code syntax is written as :
   maxScore = int(input("Maximum Possible Score: "))

Next, we need to create another variable and call it , say, yourScore, in order to get the values of scores obtained in the exams by different users or candidates. The code for this is as follows:
   yourScore = int(input("Your Score: "))
N

Now that we have created the above variables to get started with our exam calculations, let us see what we need to do next!

CREATING VARIABLES TO CALCULATE SCORE
We create a variable called percentScore to calculate the percentage score for the exam and here we need to perform the actual calculation to get the output. 
   percentScore = float(yourScore/maxScore * 100)

The t
The above calculation is actually performing division and multiplication. You are dividing yourScore by maxScore and then multiplying the resultant number by 100 to get the percentage marks. Here you will note that we are using the float() function while performing the calculation, since we want to get the exact decimal number result after performing the calculation. Some marks may be in the form of fractions, and we want to convert those fractions to decimal numbers while calculating the result to get more accurate exam marks!

The next step would involve rounding off the percentage score to two decimal places and for performing this task, we use the round() function as shown below in the code.
   percentScore = round(percentScore, 2)

NeWext
We use the print() function to print out the result as shown here. If you notice carefully, the sentence Your Percentage score is is within strings followed by a comma, and then we write the variable which in this case percentScore and remember, we can not use strings for a variable.

USING  IF-ELIF-ELSE LOOP TO WRITE MARKS & GRADE
This loop helps us to evaluate different conditions of the marks obtained in order to calculate the percentage score and also the grade in different situationsl The detailed explanation is given below the following code.

   print("Your Percentage Score is: ", percentScore)

If the person scores more than 90,% or he gets 90%,  he gets an A grade, if he gets more than 80 % ,  or 80%, he also gets A grade , if he gets more than or equal to 70%,he gets a B grade and if he gets a percentage of greater or equal to 60% the he gets a C grade and if gets more than or equal to 50%, he gets a D grade and if he gets less than 50% , he gets a U grade.

As you can see in the loop that if gives the output for the first conditional statement, elif gives the output for various other conditions following the first condition, in case the first condition is not met, and the last condition is mett by the else in the loop as else will bring out the result for the last condition in the loop when all the other conditions are not met in the loop, in which case, the last condition is met by default.
We also show the different emotions like grinning face, angry face etc based on the various output of the conditions. For showing the various emojis, we use the CLDR short names and this is reqpresented by writing the emotion within a curly brace, for example, for showing 'grinning face', we write :
       print("\N{grinning face}")
F
F
For showing an emoji for angry face, we write :
       print("\N{angry face}")

Code for the main.py 
   print("Exam Grade Calculator")
   examName = input("What is the name of the exam?: ")
   maxScore = int(input("Maximum Possible Score: "))
   yourScore = int(input("Your Score: "))
   percentScore = float(yourScore/maxScore * 100)
   percentScore = round(percentScore, 2)
   print("Your Percentage Score is: ", percentScore)
     if (percentScore >= 90):
       print("You got ", percentScore, "%", "which is a A+","\N{smiling face with sunglasses}")
     elif (percentScore >= 80):
       print("You got ", percentScore, "% which is a A", "\N{face with tears of joy}")
     elif (percentScore >= 70):
       print("You got ", percentScore, "%, which is a B", "\N{grinning face}")
     elif (percentScore >= 60):
       print("You got ", percentScore, "%, which is a C", "\N{zipper-mouth face}")
     elif (percentScore >= 50):
       print("You got ", percentScore, "%, which is a D","\N{unamused face}")
     else:
       print("You got ", percentScore, "%, which is a U", "\N{angry face}")


SOURCE CODE
You may take a look at the source code in my github


CONCLUSION

You just learnt how to build a python exam grade calculator
in few lines of code! Do remember to comment, follow and
share this post among your friends if you find this useful.

Happy coding!!










Comments

Popular Posts

Build A Random Quote Machine in React

A Simple Guide to Promises in JavaScript ES6

Welcome to my first Blog Post

How To Fight Programmer's Imposter Syndrome

Top Free Online Websites to Learn Coding

Build A Calculator in React

Guide to Learn Coding Efficiently and Effectively