Loading proofofbrain-blog...

PYTHON TUTORIAL | How to Calculate Sum and Average of a given list | And How to Calculate the Sum and Average using while loop in python

Good evening all!

Welcome to my blog. It has been long I posted in this reputable community. But today I decided to engage you with my python programming tutorial again, Hope you enjoy it!

We all know that python is a scripting language. It is a scripting language because it's source code is interpreted to an object code by an a program translator known as Interpreter!!

According to Wikipedia, as edited January 17 (2022),

Python is an interpreted high-level general-purpose programming language. Its design philosophy emphasizes code readability with its use of significant indentation. Its language constructs as well as its object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects. source.

With this little explanation of python, I believe that you have had the basic knowledge of what python is all about! So coming to what I have for you today which encompasses the following Programming topics:

  • How to Calculate the Sum and Average of a given list. And
  • How to Calculate Sum and Average using while loop

From this sequence, hence, I will proceed with the first Programming topic.


1. How to Calculate the Sum and Average of a given list


I will guide this with a screenshot. I have an Android python IDE called "Pyroid" which is used to run python source codes on Android mobile phones!

Source Code
Screenshot_20220127-231401.jpg

Output

Screenshot_20220127-231411.jpg

If you deem closely to the source code above, you will notice that there are 14 lines of codes, but if you exclude the whitespaces, it becomes 7 lines of codes.
Don't understand the program? Don't worry, make some research about python programming language and you will understand more!

If you look up, you will see the output of the source code. Line 5 is a for loop that executes untill a certain condition is met! Line 12 and 14 printed the result/output to the screen so that the user can see it.


2. How to Calculate Sum and Average using while loop

While loop is one of the control structures we have in Programming entirely. Others include; for loop, and do while. We all know what is sum and what is Average already!

Source Code

Screenshot_20220127-234154.jpg

Output

Screenshot_20220127-231738.jpg

From the source code and the output above, we can see that line 7 performs the function of executing the statement untill all the sum has been calculated.

Thank you for bringing out your time to read my post till the end!!



H2
H3
H4
3 columns
2 columns
1 column
2 Comments