CBSE Class 11 Computer Science Question 37 of 39

Conditional and Looping Constructs — Question 37

Back to all questions
37
Question

Question 21(a)

WAP to print the following pattern:

*
* *
* * *
* * * *
* * * * *
Solution
n = 5

for i in range(1, n + 1):
    for j in range(i):
        print("* ", end="")
    print()
Output
* 
* *
* * *
* * * *
* * * * *
Answer

n
=
5
for
i
in
range
(
1
,
n
+
1
):
for
j
in
range
(
i
):
print
(
"* "
,
end
=
""
)
print
()
Output
*
* *
* * *
* * * *
* * * * *