Python Programs

9
Jul

LCM of Two Numbers

Question:

Program to find the LCM of two numbers

Program:

Explanation:

A common multiple is a number that is a multiple of two or more numbers. The common multiples of 3 and 4 are 0, 12, 24, …. The least common multiple(LCM) of two numbers is the smallest number (not zero) that is a multiple of both.

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

The Palindrome Program

Question 

Write a python program to check whether given string is palindrome or not without using any inbuilt function to reverse the string

Program:

Explanation:

A palindrome is a string which is same read forward or backwards. Dad is a palindrome while Python is not.

In the program, we first accept the string to ‘string’. Since capital letters and small letters are perceived differently because of difference in ASCII codes, we convert the string to all lower for uniformity using inbuilt function ‘x.lower()’ where x is the string

In the above program, we have used the slice operator to reverese the string.The slice operator[n:m:p] returns the part of the string from nth to the (m-1)th character Setting p to -1 returns the reverse order of the slice of string you asked for. Since here we want the whole string, we use the shorthand [::-1]

Compare both the string and it’s reversal. If they are equal, then it’s a palindrome, otherwise not.

Output:

1.

2.
Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Python Armstrong program

Question 2

Write a Python program to check whether a given number is armstrong or not.

Program:

Explanation:

Armstrong number is the number whose sum of cube of individual digits is equal to the number itself.

Output:

1.

2.
Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

The Fibonacci Sequence

Question:

Program to print the Fibonacci Number

Program:

Explanation:

A Fibonacci sequence is the integer sequence of 0, 1, 1, 2, 3, 5, 8….

The first two terms are 0 and 1. All other terms are obtained by adding the preceding two terms

Ex: 5th term is sum of 4th and 3rd term;3=2+1

Output:

1.

2.
3.
Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
9
Jul

Multiplication Table

Question;

Write a program to print the multiplication table of a number

Program:

Output:
Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here
1
Jul

Print Python Built-In Function Documentation

Question:
Write a program to print some Python built-in functions documents, such as abs(), int(), raw_input(). The built-in document method is __doc__.

Program:

Explanation:

Python documentation strings (or docstrings) provide a convenient way of associating  documentation  with  Python  modules, functions, classes, and methods. An object’s docsting is defined by including a string constant as the first statement in the object’s definition

Output:

Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here