Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I keep getting an error when I answer this question: Assume the availability of

ID: 3764504 • Letter: I

Question

I keep getting an error when I answer this question: Assume the availability of a function called printStars. The function receives an integer value as an argument. If the argument is positive, the function prints (to standard output) the given number of asterisks. Thus, if printStars(8) is called, ******** (8 asterisks) will be printed. Assume further that the variable starCount has been declared and initialized to contain a positive integer value.

Write some code that prints starCount asterisks to standard output by:

first printing a single asterisk and no other characters

then calls printStars to print the remaining asterisks.

my code is:

print("*",printStars(starCount))

the output that I get is: ********* None

which is wrong. Where is the "None" coming from?!!!

This is in Python

Explanation / Answer

"None" is coming because function expects you return something but you did not mention any return statement so it is returning none. So if you mention return " " statement in the end of your defined function then output will come perfect.

And other thing in statement

print("*",printStars(starCount)) your function is not returning anything so second argument will be blank. So you have print your output in function itself like below

def create_pyramid(starCount):
    print('*')
    for i in range(starCount):
        print('*'),
    return " "
create_pyramid(8)