Build a Number Pattern Generator - Build a Number Pattern Generator

Tell us what’s happening:

Test 6 will not pass, even though it is displayed to the terminal.

Your code so far

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

print(number_pattern(-1.2))
print(number_pattern(12))
print(number_pattern(0))
print(number_pattern(-5))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.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

Welcome to the forum @matthew.cranswick,

If the argument passed to the function is not an integer value, the function should return Argument must be an integer value.

Can you say how this code is checking if n is an integer?

What if n is a string or a boolean?

Happy coding

Doh. I had tried the “if not isinstance” statement previously, but still got the error. It works now.