0% found this document useful (0 votes)
4 views6 pages

Python Programs for Number Checks

The document contains six Python programs that demonstrate various mathematical checks and calculations. These include checking for Armstrong numbers, finding prime numbers within a range, determining if a number is prime, checking if a number is a Fibonacci number, calculating the sum of squares of the first n natural numbers, and computing the cube of the sum of the first n natural numbers. Each program includes user input prompts and outputs the results accordingly.

Uploaded by

skylvr2003
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Python Programs for Number Checks

The document contains six Python programs that demonstrate various mathematical checks and calculations. These include checking for Armstrong numbers, finding prime numbers within a range, determining if a number is prime, checking if a number is a Fibonacci number, calculating the sum of squares of the first n natural numbers, and computing the cube of the sum of the first n natural numbers. Each program includes user input prompts and outputs the results accordingly.

Uploaded by

skylvr2003
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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 :

You might also like