Build a Number Pattern Generator - Build a Number Pattern Generator

Tell us what’s happening:

I am stuck with no way of figuring out a way forward

Your code so far

def number_pattern(n):
    for n in number_pattern:
        if n in range(n, n + 1):
            return n
        if number_pattern(4):
            return number_pattern

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36

Challenge Information:

Build a Number Pattern Generator - Build a Number Pattern Generator

Hi @crocnate18

To help you debug, try calling the function with an argument inside a print call.

Happy coding

Hi there,

It looks like you may not be understanding what the number_pattern function is supposed to return.

You may want to start by putting “first things first” and implementing User Story #4 and #5. These requirements ask you to validate that the n parameter passed to your function is a number that is greater than 0. It always makes sense to validate parameters first, so you know they are what you expect before you try to use them.

And then User Story #3 says, " number_pattern(n) should return a string with all the integers starting from 1 up to n (included) separated by a space."

So, if you call your function like this to test it, it should return the string “1 2 3 4”: print(number_pattern(4))

Hopefully, I’ve explained well enough that you’re comfortable giving this another try.

Happy coding!

this is where I landed and i’m stuck again

def number_pattern(n):

result = ""

for n in range(1, n + 1):

if n == 1:

        result += str(n)

else:

        result += " " + str(n)

return result

if not isinstance(n, int):

return “Argument must be an integer value.”

if n < 1:

return “Argument must be an integer greater than 0.”

Please update your code so that it is readable, as indentation is an important syntax structure in Python, it’s important to format the code so the indentation is preserved.

When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add the backticks.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

def number_pattern(n):
    result = ""
    for n in range(1, n + 1):
        if n == 1:
            result += str(n)
        else:
            result += " " + str(n)
    
    return result

    if not isinstance(n, int):
        return "Argument must be an integer value."
    
    if n < 1:
        return "Argument must be an integer greater than 0."*strong text*`Preformatted text`

do you see this?
this one will run and then nothing after it is executed, meaning the two if statements after are ignored


def number_pattern(n):
    result = ""
    for n in range(1, n + 1):
        if n == 1:
            result += str(n)
        else:
            result += " " + str(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."

    return result

consider what happens here if n is a string, will that work? maybe you need to validate that the input is as wanted before using it

Does it make sense to validate n AFTER you use n in your code?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.