Write a python program to get five marks using list and display the marks in pie chart
What we are going to do now?
In this experiment we are going to get five marks of the student form the user and displaying the marks in pie chart.
To implement this experiment we need to use two libraries in this program.
You can install “matplotlib” using the below pip command.
pip install matplotlib
You can install “numpy” using the below command.
pip install numpy
If you don’t know where to install the above mentioned library. No problem here I will give you a brief explanation.
Step1 : In your pc or laptop search the command prompt
Step 2 : Type the above mentioned commands in the command prompt.
So that’s all about installing libraries in python.
1. We are going to import libraries and creating a empty list named as marks to store the marks and creating a another list named as subjects which holds the subject name.
2.Creating a while loop to get a mark as input from the user .
while loop
The while loop in Python is used to iterate over a block of code as long as the test expression (condition) is true. We generally use this loop when we don’t know the number of times to iterate beforehand.
we are using append () that is what built in function add the item in a list .
3.Creating a for loop to print all the marks using format() function.
for loop:
for loops are used for sequential traversal. For example: traversing a list or string or array etc. In Python, there is no C style for loop, i.e., for (i=0; i<n; i++). There is “for in” loop which is similar to for each loop in other languages.
format() function
The format() function used with strings is very versatile and powerful function used for formatting strings. The curly braces {} are used as placeholders or replacement fields which get replaced along with format() function.
Output:
Here’s the full code
To learn more about python sign in to Guvi