CBSE Class 11 Computer Science Question 38 of 43

Flow of Control — Question 33

Back to all questions
33
Question

Question 25d

Write programs using nested loops to produce the following patterns:

2
4 4
6 6 6
8 8 8 8

Solution
for i in range(2, 10, 2) :
    for j in range(2, i + 1, 2) :
        print(i, end = ' ')
    print()
Output
2 
4 4 
6 6 6
8 8 8 8
Answer

for
i
in
range
(
2
,
10
,
2
) :
for
j
in
range
(
2
,
i
+
1
,
2
) :
print
(
i
,
end
=
' '
)
print
()
Output
2
4 4
6 6 6
8 8 8 8