Objectives 3, 4, and 5 are rejected, and I think I know why but I’m not sure how to elegantly solve it. It doesn’t want an extra space at the end of the list of numbers.
Entering 0.4 gives
Argument must be an integer value.
Argument must be an integer greater than 0.
Entering -2 gives
Argument must be an integer greater than 0.
Entering False gives
Argument must be an integer greater than 0.
Entering True gives
1
Entering any string (in this case, “blah”) gives
Traceback (most recent call last):
File “main.py”, line 12, in
NameError: name ‘blah’ is not defined
Entering any positive integer works just fine.
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."
else:
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/142.0.0.0 Safari/537.36
Challenge Information:
Build a Number Pattern Generator - Build a Number Pattern Generator
please create your own topic to ask questions about the challenge
If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Get Help > Ask for Help button located on the challenge.
The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.