Hello everyone!
As we all know that python is a programming language and also also a scripting language. It is called a scripting language because it is an interpreted Language meaning that it uses interpreter to translate and run it's code. Python also have many applications of which the most popular Application areas are:
- Web development
- GUI application
- Data science and artificial intelligence
I want to tutor you on how to use python to write some programs in our computer!
1. How to Calculate the Sum of n Natural Numbers
We all know what natural numbers are. And if you don't know what natural numbers are let me quickly tell you what they are. Natural numbers are those numbers used for counting and ordering! They are positive whole numbers and does not include zero and negative numbers. E.gs. are; 1, 2, 3, 4, 5, 6, 7, 8, 9, ..., n.
So we want to use python program to calculate the sum of n Natural Numbers.
Source code
n = input("Enter Number to calculate sum")
n = int (n)
sum = 0
for num in range(0,n+1,1):
sum = sum+num
print("SUM of first ", n, "numbers is: ", sum )
Output:
Enter Number to calculate sum
SUM of first 5 numbers is: 15
As you can see in the above program, we have six source lines of codes which means that the python interpreter will translate these codes line by line to machine understandable language.
As we all know, the above source codes are written in human readable form(high-level language) and the computer we're giving these instructions does not understand this language, so there must be a program translator to translate it from high-level language to low-level language, in this case, the interpreter.
2. How to Calculate the Average of first n natural numbers
All of us know what is average! But in case if you don't know, let me quickly tell you what an average is. An average is the sum of numbers divided by the total number.
E.g. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
The average of these numbers is calculated thus; 1+2+3+4+5+6+7+8+9+10/10 = 55/10
= 5.5
Therefore, the average of these numbers is 5.5
Source code:
print ("calculate an average of first n natural numbers")
n = input("Enter Number: ")
n = int (n)
average = 0
sum = 0
for num in range(0,n+1,1):
sum = sum+num;
average = sum / n
print("Average of first ", n, "number is: ", average)
Output:
calculate an average of first n natural numbers
Enter Number: 5
Average of first 5 number is: 3.0
So students, these programs are up and running if you have any python IDE installed in your Mobile Phone.
*Tips: Go to Google playstore and download pyroid 3!
Conclusion
Python is a programming language that is very easy to learn and understand. You don't have to declare variables as seen in other programing languages like C, C++, Java, e.t.c. Python does not include any preprocessor directives as seen in C++. So with this I can say that python is a good memory management application because it doesn't consume much space and time, hence efficient!
Thanks for the knowledge!!
Python is such an interesting programming software, had the opportunity to learn years back but my brain just couldn't😆😆
you've simplified it and i look forward to more teachings [If my brain can still handle😂]
Congratulations @anyiglobal! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):
Your next target is to reach 300 upvotes.
You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Check out the last post from @hivebuzz:
Support the HiveBuzz project. Vote for our proposal!
You can put your code enclosed by three starting (```) backticks and three ending same backticks. This will help to keep same indentation as in code while posting. For more, you can read here:
https://docs.github.com/en/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax
This can help you properly format your writing here in hive as well. I hope you will find it useful.