Python Programs
Python Programs
if num == 1:
print(num, "is not a prime number")
elif num > 1:
# check for factors
for i in range(2, num):
if (num % i) == 0:
# if factor is found, set flag to True
flag = True
# break out of loop
break
Output:
Enter a number greater than 1 : 13
13 is prime Number
Output:
How many terms?
6
Fibonacci sequence:
Python Programming Solutions part 1
0
1
1
2
3
5
a = 12
b = 18
Output:
The GCD of 12 and 18 is 6
# define a function
def compute_hcf(x, y):
num1 = 54
num2 = 24
Output:
The H.C.F. is 6
l=list()
while num!=0:
r=num%2
l.append(r)
num=num//2
l.reverse()
print(*l)
Output:
110
153
= 1 + 125 + 27
= 153
Code:
# take input from the user
num = int(input("Enter a number: "))
# initialize sum
sum = 0
Output:
Enter a number:
153
153 is an Armstrong number
Python
Program to
check
Palindrome
number.
Sol:
Python Programming Solutions part 1
Code:
num = int(input("Enter a number: "))
temp = num
rev = 0
while temp != 0:
rev = (rev * 10) + (temp % 10)
temp //= 10
if num == rev:
print(num,"Number is palindrome")
else:
print(num,"Number is not palindrome")
Output:
Enter a number:
242
242 Number is palindrome