I need help with Build a Number Pattern Generator

I’m getting an error for the first test case of number_pattern(4) but I’m print the correct answer. I assume I could write the code better, but I do not see how/why I am not passing the tests. If someone could point out where I am going wrong I’d greatly appreciate it. Here is my code:

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

print(number_pattern(4)) # 1 2 3 4
print(number_pattern(12)) # 1 2 3 4 5 6 7 8 9 10 11 12 
print(number_pattern("12")) # Argument must be an integer value
print(number_pattern(0)) # Argument must be an integer greater than 0

I forgot to add .strip() and the periods so never mind but I was not able to delete my post - sorry

1 Like