You are on page 1of 5

2.

Write a Python program to print all even numbers between 1 to 100 using while

loop.

i=1

while(i<=100):

if(i%2==0):

print("no's are=",i)

i=i+1

3. Write a Python program to find the sum of first 10 natural numbers using for loop.

sum=0

for i in range(1,11):

sum=sum+i

print("sum=",sum)
4. Write a Python program to print Fibonacci series.

n=int(input("enter a nmber"))

n1=0

n2=1

print("n1=",n1)

print("n2=",n2)

for i in range(3,n+1):

sum=n1+n2

n1=n2

n2=sum

print(sum)

5. Write a Python program to calculate factorial of a number

n=int(input("enter a number"))
fact=1

for i in range(1,n+1):

fact=fact*i

print("fact=",fact)

6. Write a Python Program to Reverse a Given Numbe

n=int(input("enter a number"))

rev=0

while(n>0):

k=n%10

rev=rev*10+k

n=n//10

print("reverse of number=",rev)

7. Write a Python program takes in a number and finds the sum of digits in a

number
n=int(input("enter a number"))

sum=0

while(n>0):

k=n%10

sum=sum+k

n=n//10

print("sum of digit=",sum)

8. Write a Python program that takes a number and checks whether it is a palindrome

or not.

n=int(input("enter a number"))

b=n

rev=0

while(n>0):

k=n%10

rev=rev*10+k

n=n//10

print("reverse no is=",rev)

if(b==rev):

print("no is palindrome number")

else:
print("no is not a palindrome number")

You might also like