Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Using Databases in Python Gettin' CRUD-y With It CRUD: Create Function

I have no idea how to work this CRUD challenge as you can see. Can anyone offer clarification as to why this is wrong?

At the beginning of the challenge, a model 'Challenge' has already been imported. Does this mean that there is no point in setting up the variables again? I set them to None as I didn't know what to do but thought there was no point resetting the variables. When the start of the question talks about taking arguments, is this an allusion to putting them in the function's starting parenthesis (i.e. to take them as arguments)? Also didn't know how to set the steps default value to 1 other than in the parenthesis but this didn't work either as: def create_challenge(name, language, steps(default=1)) - it just read as syntax error. Didn't get the bit where it asked to create Challenge from the arguments?! Why would I need to reconstruct Challenge if I had already imported it from models? I basically don't get the whole thing.

crud.py
from models import Challenge

def create_challenge(name, language, steps):
    name = None
    language = None
    steps = None(default=1)

    if name:
        Challenge.create(content=name)

1 Answer

Steven Parker
Steven Parker
231,248 Points

:point_right: You don't want to reassign the incoming arguments before you use them.

It seems the whole point of this function is to provide a version of the .create method that supplies a default for steps.

Here's how I did it:

def create_challenge(name, language, steps=1):
    Challenge.create(name=name, language=language, steps=steps)