Question: Write a function which outputs as many crosses as the parameter 'numCrosses' indicates. def stars ( numCrosses ) : For example, when parameter 'numCrosses' equals

Write a function which outputs as many crosses
as the parameter 'numCrosses' indicates.
def stars(numCrosses):
For example, when parameter 'numCrosses' equals 5,
the function displays the following:
+++++++++++++++
You are not allowed to use string "concatenation" or multiplication.
Also the use ofa list and appending to a listis not permitted.
You must solve the problem using 2 loops (one 'for' loop nested in the other).
Concatenation:
# String Concatenation means adding two strings together A ="Hi!" B = "Hello" C = A +""+ B print (C) # Shows: Hi! Hello
Hints:
[ be sure to type the examples below, copy/pasting will give you errors! ]
Remember:
print (1)
print (2)
Shows:
1
2
But:
print (1, end='') # end ='' prevents new line from happening
print (2)
Shows:
12
If we do:
for row in range(0,4,1):
print ('*')
We get:
*
*
*
*
We need to add more extra star with each additional row:
* # add zero extra stars at row 0
** # add1extra star at row 1
*** # add2extra stars at row 2
**** # add3extra 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): # loop 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
The code above needs to be in a function.

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 Programming Questions!