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 trialVittorio Somaschini
33,371 PointsCreate a function named create_challenge() that takes name, language, and steps arguments.
Hello.
So, we want to create this function that takes 3 arguments and creates the Challenge using those 3 arguments and I am stuck:
from models import Challenge
def create_challenge(name, language, steps):
Challenge.create
This is where I am stuck, I have defined the function and I presume it is ok, but I do not know how to have the content of the Challenge that we need to create from to all the 3 arguments, how do we write this?
I have tried to look at the peewee docs but couldn't come up with a solution.
Any help?
Thanks
Vittorio
from models import Challenge
def create_challenge(name, language, steps):
Challenge.create
6 Answers
Kenneth Love
Treehouse Guest TeacherWe use .create()
to create a Student
in the course. Do the same thing to create a Challenge
in the challenge.
Anthony Twietmeyer
661 PointsYes, indeed, in an earlier exercise we used the format for supplying the arguments for creating a Student. The peewee documentation doesn't seem to show the data being passed on separate lines. Is that a requirement?
Thanks!
Kenneth Love
Treehouse Guest TeacherNo, the separate lines aren't required.
Vittorio Somaschini
33,371 PointsThanks everyone for helping out.
I have passed the challenge with the following code:
from models import Challenge
def create_challenge(name, language, steps):
Challenge.create(name=name, language=language, steps=steps)
But I am not sure about the steps part: Steps should be optional, so give it a default value of 1.
I have basically ignored it, I was setting steps=1 on the last line of code as I thought that was the way to do it, but I passed with steps=steps which I am not 100% understanding as we should set the steps to 1 ..
I am not 100% sure the code I finally came out with is 100% correct..
Or am I wrong?
Kenneth Love
Treehouse Guest TeacherHow do you make an argument to a function optional? In other words, you need to provide a default value for the argument. We've done that in at least 2 other courses.
EDIT:
And, other than that, your code looks great!
Dan K
10,689 PointsThis code worked for me:
from models import Challenge
def create_challenge(name, language, steps=1): Challenge.create(name=name, language=language, steps=steps)
Brandon Meredith
29,350 PointsWithout directly giving the answer
From the peewee documentation:
user = User.create(username='admin', password='test')
"User" being your model, and of course the values of each field pertaining to the arguments passed to the function. Hope this helps.
https://peewee.readthedocs.org/en/latest/peewee/api.html?highlight=create#Model.create
Anthony Twietmeyer
661 PointsVittorio, look ahead to the next 'exercise' to see how the coding looks.
Stéphane Diez
19,350 Pointssteps making optional 1 is like this:
def function(steps=1)
right ?
Vittorio Somaschini
33,371 PointsThanks Kenneth.
Had some dust in my brain on this. I have now added the correction inside the arguments and checked it in the code challenge.
Much appreciated!
Vittorio
Anthony Twietmeyer
661 PointsAnthony Twietmeyer
661 PointsI'm with you Vittorio. Did the answer given give you any help. It didn't give me any help. Still stuck.