Build a Number Pattern Generator - Build a Number Pattern Generator

Tell us what’s happening:

I’m able to give the output but not what the task ask. i feel stuck from what I need to do to complete the task. I tried some codes from the forum, but I guess it’s best to make for my own so that I could understand it (even though at the end it would be a similar code)

Your code so far

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

print(number_pattern(4))
print(number_pattern(12))



    



        



         
        

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36

Challenge Information:

Build a Number Pattern Generator - Build a Number Pattern Generator

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-number-pattern-generator/6842a6cd9836f0114a5b7a8a.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @feliciaparamitha20,

Try printing num after each line within the loop, so you can see what your code is doing.

And make sure you are implementing this user story correctly:

number_pattern(n) should return a string with all the integers starting from 1 up to n (included) separated by a space. For example, number_pattern(4) should return the string 1 2 3 4.

Happy coding

Thanks for the help, I’m now able to return the correct answer. Just need to think about the hidden spaces at the end of answer!