Practice Programs Solution
Practice Programs Solution
Practice Programs Solution
1. Python Program to take three numbers from the user and print the
greatest number.
3. Write a program to print any person is eligible for vote or not (age should
not less than 18 for voting).
if s == int(x):
print("Armstrong number")
else:
print("Not an Armstrong number")
5. Write a program to check whether a number entered by user is Prime or
not.
import math
x = int(input("Enter a Number : "))
f=0
if x<2:
print("Not a Prime Number")
else:
for i in range(2,int(math.sqrt(x)+1)):
if x%i==0:
f=1
break
if f==0:
print("Prime Number")
else:
print("Not a Prime Number")
6. Write a program to calculate factorial of a number entered by user.
if num==rev:
print("Palindrome Number")
else:
print("Not a Palindrome Number")
OR
if x==rev:
print("Palindrome Number")
else:
print("Not a Palindrome Number")
8. Write a program to print all Prime numbers between given range.
x = int(input("From: "))
y = int(input("To: "))
print("Prime Numbers between",x,"and",y)
for i in range(x,y+1):
f=0
for j in range(2,i):
if i%j==0:
f=1
break
if f==0:
print(i,end=' ')
9. Write a program to print n-th Fibonacci number.
import math
import sys
x = int(input("Enter a number: "))
if x==0:
print("Fibonacci Number")
sys.exit()
a = math.sqrt(5*x*x-4)
b = math.sqrt(5*x*x+4)
if a.is_integer() or b.is_integer():
print("Fibonacci Number")
else:
print("Not a Fibonacci Number")
11. Write a program for Sum of squares of first n natural numbers.
Ex: if Input: N = 4
Then Output: 30
12 + 22 + 32 + 42 = 1 + 4 + 9 + 16 = 30