104k views
3 votes
Assignment 6: Code Snippet

Use the code snippet provided below as the basis for your work on each question in Assignment 6. Note that you may need more than two for loops for shapes in some of the questions. It wants me to use this code.

for i in range(3):
for j in range(3-i):
print("*", end=" ")
print("")


how do I create this?
FIRST
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *


I need help with this computer science python problem

User Nicolas Wu
by
6.2k points

1 Answer

4 votes

Answer:

for i in range(1, 10):

for j in range(i):

print("*", end=" ")

print("")

Step-by-step explanation:

Create a nested for loop. First loop represents the rows and the second one represents the columns. Since there are 9 rows, first loop iterates 9 times. Since each row has number of asterisk that corresponds to value of i, the second loop iterates "i" times for each iteration of the first loop and prints the asterisks. There is an empty print statement inside the second loop that makes sure that the code starts with a new line after each iteration of the second loop.

User NightEye
by
7.1k points