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 Python Collections (2016, retired 2019) Dictionaries Teacher Stats

am having problems on many things so far i feel like i don't recall everything i have been learning up to now

creating a function with an argument

teachers.py
# The dictionary will look something like:
# {'Andrew Chalkley': ['jQuery Basics', 'Node.js Basics'],
#  'Kenneth Love': ['Python Basics', 'Python Collections']}
#
# Each key will be a Teacher and the value will be a list of courses.
#
# Your code goes below here.

def num_teachers int():
    teachers = {"Andrew Chalkey":["jQuery Basics","Node.js Basics"],"Kenneth Love":["python Basics","Python collections"]}
    for teacher in teachers:
        print("

1 Answer

Cameron S
Cameron S
20,537 Points

in regards to this code challenge, you need to make sure you are properly setting up your function num_teachers(). In the challenge, num_teachers() takes a single argument which will be a dictionary of Treehouse teachers. You need to return an integer of the total number of teachers.

1st step would be provide your num_teachers function with an argument to pass your teachers dict into, like so:

def num_teachers(teachers):
     ...

Next set a variable (in this case named count) equal to 0 prior to going into the for loop. Witin the for loop set count to its current value + 1. So for each item in the teachers dict, the count variable will increase by 1. After the for loop completes, return count to get the total (int) of teachers in the dict.

My solution is:

teachers = {
    "Andrew Chalkley": ["jQuery Basics", "Node.js Basics"],
    "Kenneth Love": ["Python Basics", "Python Collections"],
}

def num_teachers(teachers):
    count = 0
    for teacher in teachers:
        count += 1
    return count

num_teachers(teachers)

Now more importantly, every programmer, regardless of experience feels like the way you are feeling. Just rewatch the videos, hack away on code that interests you and read other peoples code. Things will eventually stick!

Louise St. Germain
Louise St. Germain
19,424 Points

Hi Cameron, I just changed your comment to an answer so that it can be given the attention it deserves. Thanks for posting!

thanks man