This document contains 8 Python programs to display various patterns using loops. The programs include: (1) displaying the first 10 natural numbers using a while loop, (2) displaying the first 10 natural numbers using a for loop, (3) displaying the first 10 natural numbers in reverse order using a while loop. The programs also demonstrate: (4) displaying the first 10 odd numbers in reverse order using a for loop, (5) displaying the first 10 even and odd numbers using for loops, (6) calculating the factorial of a number, (7) displaying a multiplication table, and (8) calculating the sum of the first 10 natural numbers using a while loop.
This document contains 8 Python programs to display various patterns using loops. The programs include: (1) displaying the first 10 natural numbers using a while loop, (2) displaying the first 10 natural numbers using a for loop, (3) displaying the first 10 natural numbers in reverse order using a while loop. The programs also demonstrate: (4) displaying the first 10 odd numbers in reverse order using a for loop, (5) displaying the first 10 even and odd numbers using for loops, (6) calculating the factorial of a number, (7) displaying a multiplication table, and (8) calculating the sum of the first 10 natural numbers using a while loop.
This document contains 8 Python programs to display various patterns using loops. The programs include: (1) displaying the first 10 natural numbers using a while loop, (2) displaying the first 10 natural numbers using a for loop, (3) displaying the first 10 natural numbers in reverse order using a while loop. The programs also demonstrate: (4) displaying the first 10 odd numbers in reverse order using a for loop, (5) displaying the first 10 even and odd numbers using for loops, (6) calculating the factorial of a number, (7) displaying a multiplication table, and (8) calculating the sum of the first 10 natural numbers using a while loop.
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)