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 starsnumCrosses:
For example, when parameter 'numCrosses' equals
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 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, copypasting will give you errors!
Remember:
print
print
Shows:
But:
print end # end prevents new line from happening
print
Shows:
If we do:
for row in range:
print
We get:
We need to add more extra star with each additional row:
# add zero extra stars at row
# addextra star at row
# addextra stars at row
# addextra stars at row
Which leads to:
for row in range:
print end # show a star, but no new line yet
for j in range row, : # 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
