1.
Python Program to check Armstrong Number
n = int(input("Enter a number: "))
s=0
temp1 = n
temp2 = n
c=0
while temp1 > 0:
temp1 = temp1//10
c+=1
while temp2 > 0:
d = temp2 % 10
s += d ** c
temp2 = temp2//10
if n == s:
print(n,"is an Armstrong number")
else:
print(n,"is not an Armstrong number")
Output :
2. Python program to print all Prime numbers in an Interval
l = int(input("Enter the lower limit: "))
u = int(input("Enter the upper limit: "))
print("Prime numbers between", l, "and", u, "are:")
for n in range(l,u+1):
if n > 1:
for i in range(2,n):
if (n % i) == 0:
break
else:
print(n)
Output :
3. Python program to check whether a number is Prime or not
n = int(input("Enter a number: "))
if n>1:
for i in range(2,n):
if (n % i) == 0:
print(n," is not a prime number")
break
else:
print(n," is a prime number")
else:
print(n," is not a prime number")
Output :
4. Python Program for How to check if a given number is Fibonacci
number?
n = int(input("enter the number : "))
f1=0
f2=1
f3 = f1+f2
while f3<=n:
f1=f2
f2=f3
f3 = f1+f2
if f2==n:
print(n," is a fibonacci number")
else:
print(n," is not a fibonacci number")
Output :
5. Python Program for Sum of squares of first n natural numbers
n = int(input("Enter thr range: "))
s=0
for i in range(1,n+1):
s += i**2
print("Sum of first ",n," is ",s)
Output :
6. Python Program for cube sum of first n natural numbers
n = int(input("Enter thr range: "))
s=0
for i in range(1,n+1):
s += i
print("cube of Sum of the first ",n," is ",s**3)
Output :