Question: Write a program which outputs as many crosses as the variable numCrosses indicates. You may NOT use string concatenation, must use nested loops. For example,

Write a program which outputs as many crosses as the variable numCrosses indicates. You may NOT use string concatenation, must use nested loops. For example, when "numCrosses" = 5, the program displays the following: + + + + + + + + + + + + + + + 

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

Remember "concatenation"? You don't get to use it ;)

Also string multiplication or using a list and appending to it is not allowed.

You must solve this using 2 loops (one for loop nested in the other).

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

# STRING CONCATENATION (Adding two strings together) A = "Hi!" B = "Hello" C = A +" "+ B print (C) # Shows: Hi! Hello 

Hints:

print(1)

print(2)

# shows

1

2

print(1,end=' ') # end = ' ' prevents new line from happening

print(2)

# shows 1 2

# If I do

for row in range(0, 4,1):

print(' * ' )

# I get

*

*

*

*

# I need to add as many extra stars (columns) as is my number of row

* # add zero extra stars at row 0

* * # add 1 extra star at row 1

* * * # add 2 extra stars at row 2

* * * * # add 3 extra stars at row 3

# which leads to

for row in range(0, 4, 1):

print (' * ', end= ' ') # show a star, but no new line yet

for j in range(0, row, 1): # happens as many times as value of row

print (' * ',end = ' ' ) # show extra stars on the same line

print() # show a new line after the extra stars

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!