Explaining python range() to a kid || Using range() to solve different problems

Опубликовано: 15 Май 2026
на канале: Letzz Doo IT
57
1

a = list(range(0,10))
b = list(range(0,10,2))
c = list(range(0,10,3))
print(a)
print(b)
print(c)

x = list(range(1,11))
print(x)

1Q. Print odd numbers from 1 to 10
y = list(range(1,10,2))
print(y)

2Q. Print even numbers from 1 to 10
output : [2,4,6,8,10]
z = list(range(2,11,2))
print(z)


i = list(range(10,0,-1))
print(i)

j = list(range(10,0,-2))
print(j)

3Q. print odd numbers from 10 to 1 (1 to 1o in reverse order)
output : [9,7,5,3,1]
k = list(range(9,0,-2))
print(k)


----------------------------------------------------------------------
Q. Print the multiplication table of a given number
2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
#
# 2 * 10 = 20

for i in range(1,11):
print("2 * ",i," =",2*i)

----------------------------------------------------------------------
list1 = [2,4,6,1,3,7,5,8,1,6,20]

Q. Add only the even numbers in the given list

num % 2 = 0

total = 0
for num in list1:
if num % 2 == 1:
print(" current num is : ",num)
total = total + num # 46
print("total of all odd numbers is : ",total)

----------------------------------------------------------------------


1. print the numbers from 5 to 15 using range()
output :
5
6
7
8
9
10
11
12
13
14
15

2. print the odd from 10 to 25 using range()
output :
11
13
15
.
.
.
25

3. print the odd numbers from 25 to 1 (1 to 25 in reverse order) using range()
output :
25
23
21
19
17
.
.
.
.
1


4. print the multiplication table in reverse order

2 * 10 = 20
.
.
2 * 3 = 6
2 * 2 = 4
2 * 1 = 2


5. In the given list, add only the values which are divisible by 3 and print the total.

list1 = [4,5,6,8,9,10,13,15,17,18,21,23,27,300,254,297]

output : 693