Home > Enterprise >  How to remove the none error from the output
How to remove the none error from the output

Time:11-20

I'm creating a recursive function that creates n lines of asterisk. I do not have problems on writing code, but just am wondering why None appears in my output.

Here is my code:

def recursive_lines(n):
    for n in range(0,n):
        print ('*'   ('*'*n)) # Print asterisk
    
print(recursive_lines(5)) # Enter an integer here

And this is the result:

*
**
***
****
*****
None

I don't think I used any int(print()) kind of statement here.. Then why does this error keep appearing?

CodePudding user response:

You are printing out recursive_lines(5), but inside the function, you are already printing the values. Simply remove the print that is around recursive_lines(5)

CodePudding user response:

The None is printing because you are using print(recursive_lines(5)) even though your function is not returning anything. Remove the print statement while calling the function.

def recursive_lines(n):
    for n in range(0,n):
        print ('*'   ('*'*n)) 
    
recursive_lines(5) 

CodePudding user response:

Your function isn't returning anything. By default it'll return none. And if you don't want it to print none you can just not print recursive_lines(5). If you add a return 0 statement it'll return 0 instead of none

  • Related