0% found this document useful (0 votes)
14 views4 pages

PWP Pra5

The document contains several Python programs demonstrating basic programming concepts. It includes examples for printing even numbers, calculating the sum of natural numbers, generating Fibonacci series, calculating factorials, reversing numbers, summing digits, and checking for palindromes. Each program is accompanied by its output format.

Uploaded by

thopteayush604
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)
14 views4 pages

PWP Pra5

The document contains several Python programs demonstrating basic programming concepts. It includes examples for printing even numbers, calculating the sum of natural numbers, generating Fibonacci series, calculating factorials, reversing numbers, summing digits, and checking for palindromes. Each program is accompanied by its output format.

Uploaded by

thopteayush604
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/ 4

2. Write a Python program to print all even number between 1 to 100 using while loop.

i=1

while(i<=100):

if(i%2==0):

print(i)

i=i+1

OUTPUT:

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

sum=0

for i in range(1,11):

sum=sum+i

print("SUM OF FIRST 10 NATURAL NUMBER:",sum)

OUTPUT:
4. Write a Python program to print Fibonacci series.
i=1

prev=0

next=1

sum=0

while(i<=5):

sum=prev+next

prev=next

next=sum

print(sum,end=" ")

i=i+1

OUTPUT:

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


num=int(input("ENTER NUMBER:"))

i=1

fact=1

while(i<=num):

fact=fact*i

i=i+1

print("FACTORIAL OF",num,"is",fact)

OUTPUT:

6. Write a Python program to reverse a given number.


num=int(input("ENTER A NUMBER:"))

rev=0

while(num>0):
rem=num%10

rev=rev*10+rem

num=num//10

print("REVERSE OF GIVEN NUMBE IS",rev)

OUTPUT:

7. Write a Python program takes in a number and finds the sum of digits in a number.
num=int(input("ENTER A NUMBER:"))

sum=0

rem=0

while(num>0):

rem=num%10

sum=sum+rem

num=num//10

print("SUM OF GIVEN NUMBER:",sum)

OUTPUT:

8. Write a Python program that’s take a number and check whether it is a palindrome or not.
num=int(input("ENTER A NUMBER:"))

temp=num

rem=0

rev=0

while(num>0):

rem=num%10

rev=rev*10+rem

num=num//10

if(temp==rev):
print("NUMBER IS PALINDROME")

else:

print("NUMBER IS NOT PALINDROME")

OUTPUT:

You might also like