Class 8_ Python Programs
Class 8_ Python Programs
2. Write a program to print all the numbers in backward order from 20 to 10.
for I in range(20, 10, -1):
print(I)
4. Print table of a number entered by user using while and for loop both.
#Using While loop
n = int(input(“Enter a number”))
i =1
while i<=10:
print(n, “*” , i , “=” , n*i)
i =i+1
5. To print all the multiples of 5 between a given range of numbers entered by the
user.
if i%5 == 0:
print(i)
6. To print sum of all the positive and negative numbers that lies between -10 to 15.
sum=0
for i in range (-10, 16):
sum =sum+i
i=i+1
print(sum)
7. Write a program using for loop to print all the even numbers starting from 2 to x,
where x is entered by the user
x = int(input(“Enter a number”))
for i in range(2, x+1):
if (n%2 ==0):
print(n)
8. Print the following pattern using looping in python.
*
**
***
****
*****
Code:
for i in range (1,6,1):
for j in range (1,I+1,1):
print(“*”, end= “ ”)
print()