Build a Number Pattern Generator - Build a Number Pattern Generator

Tell us what’s happening:

Hi, I hope you are having a nice day! I can’t figure out what is going wrong here. It is returning the space separated values, but what is missing? I’m getting an X for these steps:

“Failed 3. number_pattern(4) should return 1 2 3 4.

Failed: 4. number_pattern(12) should return 1 2 3 4 5 6 7 8 9 10 11 12.

Failed: 5. number_pattern should return a space separated list of numbers for any positive integer.”

Your code so far

def number_pattern(n):
    num_string = ""
    if not isinstance(n,int): 
        return "Argument must be an integer value."
    if n <= 0:
        return "Argument must be an integer greater than 0."
    else:    
        for num in range(1,n +1):
            num_string += str(num) + " "
        return num_string

print(number_pattern(12))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0

Challenge Information:

Build a Number Pattern Generator - Build a Number Pattern Generator

I have added repr like this print(repr(number_pattern(12))) to see that your function returns '1 2 3 4 5 6 7 8 9 10 11 12 ', do you see the difference with the requested output?

You need to use the strip() method to remove extra spaces.

Hi Thank you for you reply! I figured it out thank you! :grin: