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

sidni ahmed
sidni ahmed
3,329 Points

Create a function named create_challenge()

I have seen this code in another post and I trying to understand it. can someone please explain why we pass 3 functions and how this code is CRUD?

thanks

crud.py
from models import Challenge


def create_challenge():
  pass

def create_challenge(name, language, steps):
  pass

def create_challenge(name, language, steps=1):
  pass

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

3 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

The code you posted is a step-by-step solution to the challenge. Each definition adds the next requirement of that Task. One would not normally code this way. In python, the last definition of an object takes precedence so the previous definitions are overwritten and only the last one is checked as the solution to the challenge.

Post back if you need more information.

sidni ahmed
sidni ahmed
3,329 Points

Thanks Chris. You're the best. I wish one day I can be good like you in python :)

paul amato
paul amato
2,707 Points

Thank you Chris, this post helped. It was not clear to me that Challenge was a table to be updated.