Social Widget

Responsive Ads Here

Wednesday, January 29, 2020

Python program for beginners - part 1


This post will have 5 simple python programs. They are

  1. print using python
  2. check palindrome
  3. Armstrong number
  4. Find the greater number
  5. print prime numbers in a range
All these programs are provided along with a code snippet in this part. More programs on the next part.

1. Print using python

This simple code snippet shows how to print using python.
The simplest way to produce output is using the print() function where you can pass zero or more expressions separated by commas. This function converts the expressions you pass into a string before writing to the screen.

2. Check palindrome

Given a string, write a python function to check if it is palindrome or not. A string is said to be palindrome if reverse of the string is same as string. For example, “radar” is palindrome, but “radix” is not palindrome.

3. Armstrong number

A positive integer of n digits is called an Armstrong number of order n (order is number of digits) if.

abcd... = pow(a,n) + pow(b,n) + pow(c,n) + pow(d,n) + ....

4. Greatest of two numbers

5. Prime numbers in a range

A positive integer greater than 1 which has no other factors except 1 and the number itself is called a prime number. 2, 3, 5, 7 etc. are prime numbers as they do not have any other factors. But 6 is not prime (it is composite) since, 2 x 3 = 6.

More programs in the next part.

1 comment:

  1. Wow! What an excellent article!!! It is very helpful for me. I’ve learnt a lot of things from this post, thank you. If anyone wants to learn more you can also visit