Posts

Python program to print factorial of a given number

Image
What are factorials? Factorial of an integer is product of that integer and all positive integers below it such that 4 factorial is equal to 4x3x2x1 = 24. Factorial is represented by "!" i.e. 4! means 4 factorial which is equal to 24. Algorithm :- Step 1- Start Step 2- Input a number Step 3- Declare variable fact and i Step 4- Initialize value              fact←1              i←2 Step 5- if i<=number                  fact=fact*i                  i=i+1                  repeat Step 5              else                   go to Step 6 Step 6- Display fact Step 7- Stop Flowchart :- Code :- number=int(input("Enter a number:")) fact=1 i=2 while i<=number: fact=fact*i i=i+1 print(fact)

Python program to determine if a given number is prime number

Image
What are prime numbers? Those numbers which have only two factors, one and the number itself are called prime numbers and the numbers with more than two factors are called composite numbers. Example of prime number:- 2,3,5,7,11,13.... Algorithm :- Step 1- Start Step 2- Input the number Step 3- Declare variable i Step 4- Initialize variable               i ← 2 Step 5- if i<number                  go to Step 6              else                  go to Step 7 Step 6- if number%i==0                  number is not prime                  go to Step 8              else i=i+1                  go to Step 5 Step 7- number is prime Step 8- Display output Step 9- Stop Flowchart :- Code :- number=int(input("Enter a number:")) for i in range(2,number): if number%i==0: print("not a prime number") break else: print("prime number")

Python program to determine if a given number is odd or even

Image
What are odd and even numbers? Those numbers which are divisble by two are called even numbers and other numbers are called odd numbers (i.e. they are not divisible by two). Algorithm:- Step 1- Start Step 2- Input the number Step 3- if n%2==0 then number is even              else number is odd Step 4- display the output Step 5- Stop Flowchart:- Code:- number=int(input("Enter a number:")) if number%2==0: print("Even number") else: print("odd number") Note:-"%" is used to get reminder i.e. 5%2 will give 1 as the output. It is known as modulus operator.

Getting started with python

Hello everyone, in this article I will be telling you guys about how to get started with python programming language. Why python? Python is one of the most popular computer programming language and it is widely used in data science and machine learning algorithms. It is high level language with very easy syntax which makes it easy for the beginners to learn python. How to install python on your computer? To install python go to the python's page -> https://www.python.org From there go to Downloads menu and download the software. Once the software is downloaded go ahead and install it as you install any other software. If you are really interested in learning python I would highly recommend you to install this software on your computer. How to install python on your phone? There are many applications which enable you to run python on your phone. I personally prefer pydroid which is available for android phone on playstore. Other ways