5.1.1 Basic Funtion Call Output

Question:

I have been trying to get this to output correctly. It is saying I’m not adding a line break at the end.

I was wondering, how I could add the line break? From my understanding the code is for the most part right.

I also need to have it take in another output that Zybooks generates itself, so I can’t just simply put two print statements of (‘*****’)

def print_pattern(): 
    print('*****') 

for i in range(2): 
    print(print_pattern()) 

Expected output:

***** 
***** 

My output:

***** 
None 
***** 
None
Asked By: oCosmic

||

Answers:

If you want your function to work, you have to return a value like this.

def print_pattern():
    return '*****'

for i in range(2):
    print(print_pattern())

You function isn’t working properly because you are trying to print something that has no return value. If you return something and try to print like I have done in my code here, it will work.

Edit.

Since you cannot change the print_pattern() function, the correct way to do this would be like this.

def print_pattern():
    print('*****')

for i in range(2):
    print_pattern()

You just do a for loop where you run the function at the end of each loop. The print function my default adds a new line at the end of the print.

Answered By: anarchy
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.