0% found this document useful (0 votes)
1 views7 pages

Experiment No.5

The document contains Python programs for various tasks including printing even numbers between 1 to 100, calculating the sum of the first 10 natural numbers, generating a Fibonacci series, calculating the factorial of a number, reversing a given number, summing the digits of a number, and checking if a number is a palindrome. Each task is accompanied by code snippets and expected outputs. The programs utilize loops and conditionals to achieve their respective functionalities.

Uploaded by

Samarjeet Patil
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)
1 views7 pages

Experiment No.5

The document contains Python programs for various tasks including printing even numbers between 1 to 100, calculating the sum of the first 10 natural numbers, generating a Fibonacci series, calculating the factorial of a number, reversing a given number, summing the digits of a number, and checking if a number is a palindrome. Each task is accompanied by code snippets and expected outputs. The programs utilize loops and conditionals to achieve their respective functionalities.

Uploaded by

Samarjeet Patil
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
You are on page 1/ 7

Q.

2] Write a Python program to print all even numbers between 1 to 100


using while loop.

Code –
print("Even numbers between 1-100 are :")
n=0
while n <= 100:
if n%2==0:
print("Even numbers between 1 - 100 are :",n)
n=n+1
Output-
Q.3] Write a Python program to find the sum of first 10 natural numbers
using for loop.

Code –
sum_of_num = 0
n=0
for n in range (1,10):
sum_of_num = sum_of_num + n
print("Sum of first 10 Natural Numbers is :",sum_of_num)

Output –
Q.4] Write a Python program to print Fibonacci Series.

Code –
num = 5
a,b=0,1
print("Fibonacci Series :")
for i in range(num):
print(a)
c = a+b
b=a
a=c

Output –
Q.5] Write a Python program to calculate the factorial of a number.

Code –
n = int(input("Enter a Number :"))
fact = 1
for i in range(1,n+1):
fact = fact*i
print(fact)

Output-
Q.6] Write a Python program to Reverse a Given number.

Code –
num = 125
rev_num = 0
while num > 0:
digit = num % 10
rev_num = rev_num * 10 + digit
num //= 10
print("Reversed Number : ",rev_num)

Output –
Q.7] Write a Python program takes in a number and finds the sum of digits in
a number.

Code -
n = int(input("Enter the Number : "))
sum_no = 0

while n > 0:
digit = n % 10
sum_no += digit
n //= 10

print("Sum of Digits in the Number are :",sum_no)

Output –
Q.8] Write a Python program takes in a number and checks whether it is a
Palindrome or not.

Code –
n = int(input("Enter a Number :"))
rev_no = 0
temp = n
while n > 0:
num = n % 10
rev_no = rev_no * 10 + num
n //= 10
if rev_no == temp:
print("Entered Number is Palindrome !")
else:
print("Entered Number is not Palindrome !")

Output –

You might also like