Monday, 23 September 2019

python examples with answers | python examples


python examples with answers | python examples






Question 1. Write a program to check given integer is Palindrome or not?

Answers:

digit=0
num=int(input("Enter number : "))
rev=0
temp=num

while(num!=0):
        digit=num%10
        num=num//10
        rev=rev*10+digit
if(rev==temp):
     print(temp," is Palindrome")
else:
     print(temp," is not Palindrome")


Screenshot:

palindrome in python

example of palindrome




Question 2. Write a program to find Fibonacci series?

0,1,1,2,3,5,8,........

Answer

first=0
second=0
num=int(input("Enter the last number to display the series"))
print(first)
print(second)
for i in range(0,num):
         third=first+second
         print(third)
         first,second=second,third

Screenshot:

fibonacci series

Question 3. Write a program to find prime number?

Answer

num=int(input("Enter any number : "))
for i in range(2,num):
          if(num%i==0):
                       print(num, " is not prime number.")
                       break
else:
    print(num," is prime number.")

Screenshot:

prime number in python



Question 4. Write a program to find Factorial?

Answer

num= int(input("Enter number : "))
fact=1

for i in range (1,num+1):
        fact=fact*i
print("Factorial is ", fact)
        
Screenshot:

factorial in python


No comments:

Post a Comment

Recent Post

Python Project | Banking System | Project on Banking System using python

  PYTHON PROJECT Banking System import csv import pandas as pd import matplotlib.pyplot as plt import sys import datetime found=False def ne...