Build a Number Pattern Generator - Build a Number Pattern Generator

Tell us what’s happening:

My code seems to work fine. I am not getting credit for #'s 3 - 5 and # 7

Your code so far

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

print(number_pattern(4))

Your browser information:

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

Challenge Information:

Build a Number Pattern Generator - Build a Number Pattern Generator

print(‘|’ + number_pattern(12) + ‘|’)

Try testing like this so you can see all of the spaces your code generates.

1 Like

Hi,

Thanks for the tip. After modifying my return value, #4 checked of. However, I am not seeing why # 4 us correct but not #3. Here is my updated code:

def number_pattern(n):
    
    if not isinstance(n,int):
        return 'Argument must be an integer value.'
    elif n <= 0:
        return 'Argument must be an integer value greater than 0.' 
    num = ''    
    for i in range(1,n+1):
        num += str(i) + ' '
    return(num[:2*(n+1)])
    
   
print(number_pattern(4))
#print('|' + number_pattern(12) + '|')

I do not like the modified return value. I am having trouble following the for loop. Can you show me or hint me an alternative?

Edit:

Something is wrong with my code. When print(number_pattern(12)) it works, but print(number_pattern(13)), a 1 occurs after the ‘12’

I have figured out the code. I changed back the return value to ‘num’ and used the strip method. Thanks!

1 Like