You are on page 1of 2

Python Programs

1. Display first 10 natural numbers using while loop.


i=0
while i<=10:
print(i)
i=i+1
2. Display first 10 natural numbers using for loop
for i in range(1,11,1):
print(i)
3. Display first 10 natural numbers in reverse order using while loop.
i=10
while i>=1:
print(i)
i=i-1
4. Display first 10 odd numbers in reverse order.
for i in range(19,0,-2):
print(i)
5. Display first 10 even numbers and Odd numbers.
i) for i in range(0,21,2):
print(i)
ii) for i in range(1,21,2):
print(i)
6. Write a program to find factorial of a number.
a=int(input('Enter any number:-'))
f=1
for i in range(1,a+1):
f=f*i
print('Factorial of a number is',f)
7.Program to display multiplication table.
n = int(input('Enter your number:'))
for i in range(1,11):
print(n ,'*' , i ,'=',n*i)
8. Program to print the sum of first natural numbers.
sum=0
i=1
while(i<=10):
sum=sum+i
i=i+1
print('Sum of first natural numbers:', sum)

You might also like