Build a Number Pattern Generator - Build a Number Pattern Generator

Tell us what’s happening:

My code is outputing the separated number list but it is not passing tests 3, 4 and 5. Can someone help me?

Your code so far

def number_pattern(n):
    if not isinstance(n, int):
        return 'Argument must be an integer value.'
    if n < 1:
        return 'Argument must be an integer greater than 0.'

    number_list = ''

    for number in range(1,n+1):
        
        number = str(number)
        number_list += number + ' '
        
    
    return((number_list))

print(number_pattern(12))
 

Your browser information:

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

Challenge Information:

Build a Number Pattern Generator - Build a Number Pattern Generator

Welcome to the forum @Samuel_Martins30 !

You’re very close. Try testing like this to see where the issue is:

print('|' + number_pattern(4) + '|')

Thank you for your welcome! I tested with what you sugested, it came with the following output: |1 2 3 4 |. Does the problem lie in the space created at the end of the output?

Yes; the tests do not expect that.

Thank you very much! I found a solution to that by using a string method!

1 Like