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

sowmya c
sowmya c
6,966 Points

teacher stats last challange

The code should show the teacher name along with the number of courses as a list.the code is giving bummer

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(str1):
    count1 = 0
    for key in str1:
        count1 += 1
    return count1   

def num_courses(str1):
    count2 = 0
    for value in str1.values():
        for items in value:
            count2 += 1
    return count2

def courses(str1):
    sow3 = []
    for value in str1.values():
        for items in value:
            sow3.append(items)
    return sow3

def most_courses(str1):
        dict4 = {}
        max4 = 0
        sow4 = ""
        maxi = 0
        for key in str1:
            for items in str1.values():
                max4 += 1
            dict4[key] = max4

        for key1 in dict4:
            if dict4[key1] > maxi:
                sow4 = key1 
                maxi = dict4[key1]
        return sow4

def stats(str1):
    listOver = []
    count = 0
    for key in str1:
        listInside = []
        listInside.append(key)
        for value in str1.vales():
            count += 1
        listInside.append(count)
        listOver.append(listInside)
    return listOver

4 Answers

Pete P
Pete P
7,613 Points

You're right, I looked again and noticed the output is incorrect. Your function is incorrectly counting the number of courses for each teacher.

A couple of fixes:

  1. Currently 'count' is outside of the first for loop. You need to re-initialize 'count' to zero inside of the first for loop. Otherwise, it will still have the count of the previous teacher's courses.

    for key in str1:
        count = 0
    
  2. I believe your second for loop should iterate through the values only in the list corresponding to the current key rather than all of the values in the dictionary:

    for value in str1[key]:
    

Hope that works out for ya! Let me know if not.

Pete P
Pete P
7,613 Points

Just a little error. You misspelled 'values' as 'vales' in your second for loop.

Should work after that's fixed.

Hope that helps!

sowmya c
sowmya c
6,966 Points

Ya corrected that still gives an error says wrong output

sowmya c
sowmya c
6,966 Points

ya thanks so much.It worked