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 trialSplotch_ P
2,984 PointsMost_courses, Treehouse Code Challenge. Task 4 of 5 in teachers.py
Can somebody look over my last function labeled "most_courses". Im not sure where I stopped making sense. Thank you peeps
# 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(dict):
num_teachz=0
for teachers in dict:
num_teachz+=1
return num_teachz
def num_courses(The_D):
num_coursies=0
for teachers in The_D:
num_coursies+= len(The_D[teachers])
return num_coursies
def courses(The_D):
A_List = []
for teachers in The_D:
A_List += The_D[teachers]
return A_List
def most_courses(The_D):
MAX_COUNT=0
WINNER=""
for teacher, courses in The_D.items():
if len(courses)>(MAX_COUNT):
MAX_COUNT=len(courses)
WINNER=teacher
return WINNNER
4 Answers
Eric M
11,546 PointsHi Theodore,
This code is actually pretty good, it looks like you might have been on a bit of a roll and enthusiastically put an extra N in WINNER
in your return statement. That's the only straight up error I see.
When it comes to coding convention however some programmers will find reading your code confusing due to your use of all caps variables. All caps variables are by convention used for constant values that don't change (during the running of the program) but still need to be hard coded in.
For example:
#Global Constants
TAX_RATE = 0.1
LEGAL_DRINKING_AGE = 18
MAX_ELEVATOR_CAPACITY_KGS = 280
Best of luck, looks like you're doing great!
Schaffer Robichaux
21,729 PointsSooo close-
- Looks like you added an extra "N" in you last statement return WINNNER
- I tested it and it provides the expected results thereafter
Cheers
Splotch_ P
2,984 PointsOEEE man, Thank you for helping me! I thought I was losing it. ive taken a break since then, but i feel good about getting back to it, thank you again.
Eric M
11,546 PointsNo sweat!
Little errors like this can cause huge headaches later on, and they're pretty common because they're so easy to make. If you write a large and complex program try using an IDE that can automatically check for this stuff like PyCharm or VS Code with a Python linter.
Vivienne Owusu-Ansah
3,142 Pointsdef most_courses(The_D): MAX_COUNT=0 name="" for teacher, courses in The_D.items(): if len(courses)>(MAX_COUNT): MAX_COUNT=len(courses)
WINNER=teacher
return WINNNER
last two lines the function must return name.
name=teacher
return name
Splotch_ P
2,984 PointsSplotch_ P
2,984 PointsDude thanks for the extra info. Im pretty new to all this and learning new things like the global constants ^. I usually play around in sublime text editor, but i was goofing around a little too much for this not thinking about; what if i got something wrong? lol. thanks so much, again.