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:
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:
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:
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:
No comments:
Post a Comment