Python Program to check Armstrong Number?
HINT : 153 = 111 + 555 + 333 // 153 is an Armstrong number.
Python Program for How to check if a given number is Fibonacci number?
HINT : A Fibonacci sequence is the integer sequence of 0, 1, 1, 2, 3, 5, 8....
The first two terms are 0 and 1.
All other terms are obtained by adding the preceding two terms.
This means to say the nth term is the sum of (n-1)th and (n-2)th term.
# Program to check Armstrong Number
num = int(input("Enter a Number: "))
sum = 0
num1 = num
while num1>0:
r = num1 % 10
sum = sum + (r*r*r)
num1 = num1 // 10
if sum == num:
print("It is a Armstrong Number")
else:
print("It is not a Armstrong Number")
Enter a Number: 153 It is a Armstrong Number
# Program to print Fibonacci Numbers
num1 = 0
num2 = 1
num = int(input("Enter no. of Fibonacci Numbers: "))
print("Fibonacci Series are: ", num1, num2, end=" ")
for i in range(2, num):
num3 = num1 + num2
num1 = num2
num2 = num3
print(num3, end=" ")
# Program to check if a number is a Fibonacci Number or not
NUM = int(input("\nEnter the number you want to check: "))
f1 = 0
f2 = 1
f3 = 1
if (NUM == 0 or NUM == 1):
print("Given number is fibonacci number")
else:
while f3 < NUM:
f3 = f1 + f2
f1 = f2
f2 = f3
if f3 == NUM:
print("Given number is fibonacci number")
else:
print("No, It’s not a fibonacci number")
Enter no. of Fibonacci Numbers: 15 Fibonacci Series are: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 Enter the number you want to check: 13 Given number is fibonacci number