# Write a program to check if the number is a prime number - Python

Categories:
Viewed: 4 - Published at: a few seconds ago

### Write a program to check if the number is a prime number

``````num = int(input("Enter a number: "))

if num > 1:
for i in range(2,num):
if (num % i) == 0:
print(num,"is not a prime number")
print(i,"times",num//i,"is",num)
break
else:
print(num,"is a prime number")

else:
print(num,"is not a prime number")
``````

### write a program to print all prime numbers between an interval

``````lower = int(input("Enter lower range: "))
upper = int(input("Enter upper range: "))

for num in range(lower,upper + 1):
if num > 1:
for i in range(2,num):
if (num % i) == 0:
break
else:
print(num)
``````

### write a program to find the factorial of a number

``````num = int(input("Enter a number: "))
factorial = 1
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
``````

### write a program to display the multiplication table of a number

``````num = int(input("Show the multiplication table of? "))
# using for loop to iterate multiplication 10 times
for i in range(1,11):
print(num,'x',i,'=',num*i)
``````

### write a program to print Fibonacci sequence

``````nterms = int(input("How many terms you want? "))
# first two terms
n1 = 0
n2 = 1
count = 2
# check if the number of terms is valid
if nterms <= 0:
print("Plese enter a positive integer")
elif nterms == 1:
print("Fibonacci sequence:")
print(n1)
else:
print("Fibonacci sequence:")
print(n1,",",n2,end=', ')
while count < nterms:
nth = n1 + n2
print(nth,end=' , ')
# update values
n1 = n2
n2 = nth
count += 1
``````

### write a program to check Armstrong number

``````num = int(input("Enter a number: "))
sum = 0
temp = num

while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10

if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
``````

### write a program to find Armstrong number in an interval

``````lower = int(input("Enter lower range: "))
upper = int(input("Enter upper range: "))

for num in range(lower,upper + 1):
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
print(num)
``````