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 trialSandu Gabriel
2,563 PointsI don't understand what I should create here. Thanks for your help.
I created a challenge with the inputs of the function and i dont understand why the code doesnt work
from models import Challenge
def create_challenge(name, language, steps):
steps = 1;
a = Challenge(name, language, steps);
1 Answer
Louise St. Germain
19,424 PointsHello Sandu,
You'll need to fix a few small things in the code for it to work.
First, it's saying steps (one of the parameters on create_challenge) should be optional, so give it a default value of 1. So this means you'll need to assign the default value right there in the parameter definition. If you do it later (as in your original code), this will make it a mandatory parameter, which is not what's asked for. This also means that once you have the default value among the parameter definitions, you don't need that steps = 1 line inside the function block.
def create_challenge(name, language, steps=1):
# etc..
(Side note: shouldn't put semicolons anywhere in this code, so you can get rid of all the semicolons.)
Next, to create an instance of Challenge, you'll need to use Challenge.create(). It takes 3 parameters, and the code needs to be modified to call them all with their names.
# Instead of...
a = Challenge(name, language, steps);
# Use...
Challenge.create(name=name, language=language, steps=steps)
I think if you make those substitutions, it should work!