Cannot complete test n6 and n7.
If n is integer, everything works perfectly, if n is not integer or a negative integer, I still get the code running but with some typo I cannot comprehend.
Also, I know i have dropped the loop but I’m not sure where to put it. I have tried to rewrite it into:
else:
pattern = “”
for i in range(1, n+1):
pattern += str(i) + “”
return pattern
but then it gives me a failed test on all but n1 and n2 parameters. Very frustrating.
Your code so far
def number_pattern(n):
if not isinstance (n, int):
print('Argument must be an integer value')
if n <1:
print('Argument must be an integer greater than 0')
return " ".join(map(str, range(1, n+1)))
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/149.0.0.0 Safari/537.36
Challenge Information:
Build a Number Pattern Generator - Build a Number Pattern Generator
punctuation got me again!!
also, i remember you or someone else saying in another post that ‘return’ finishes the loop, that’s why i put print instead. i guess i’m still struggling with understanding the basic function of both. thank you anyway!
that’s the thing, i didn’t follow instructions to a T but i’ve used the functions dictionary and it got me here with the code that i wrote.
additionally, when i did try to implement a loop (not only what i wrote in my second post but multiple others), i had an error one way or another and eventually i gave up and posted this code with another problem i was stuck on here (turns out it was very trivial)
the program accepted my code anyway, but i will gladly listen to your advice/suggestions with how to implement a loop here
Try thinking of it this way: If n is a string instead of the expected int, and you just print a message to the console, it doesn’t stop the system from continuing to process your code. But return does, so you avoid an unhandled error down the line.
You could’ve used the loop you referenced in your original post with a couple of small tweaks like concatenating a string with a space in it instead of an empty string to str(i), but as long as you understand what it’s doing, the code you wrote looks elegant.