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 of a list and appending to a list is 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:
1 2
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
* * # 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): # 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.