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

Printing challenge programs in Python 3.4

I am trying to create programs in python 3.4 all the challenge tasks but unable to print any of the outputs from the function. When I run nothing happens.

Here is the example:

dict_teachers = {'Jason Seifer': ['Ruby Foundations', 'Ruby on Rails Forms', 'Technology Foundations'],
  'Kenneth Love': ['Python Basics', 'Python Collections']}
def most_classes(dict_teachers):
  max_count = 0
  for keys, values in dict_teachers.items():
    if len(values) > max_count:
      max_count = len(values)
      busy_teacher = keys
  return busy_teacher
  print(busy_teacher)

def num_teachers(dict_teachers):
  return len(dict_teachers.keys())

def stats(dict_teachers):
  teachers_list = []
  for keys in dict_teachers:
    teachers_list.append([keys, len(dict_teachers[keys])])
  return teachers_list
  print(teachers_list)

def course(dict_teachers):
  course = []
  for keys in dict_teachers:
    course.extend(dict_teachers[keys])
  return course
  print (course)

Fixed markdown for the posted code. If you're curious about how to add markdown like this on your own, checkout this thread on posting code to the forum . Also, there is a link at the bottom called Markdown Cheatsheet that gives a brief overview of how to add markdown to your posts.

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

When you run a script (instead of just using it in the Python shell), and your script uses return everywhere (as it usually should), you won't see output because the output went back to Python itself.

Below your code, in your script, add lines like:

print(most_classes(dict_teachers))
print(courses(dict_teachers))

Thanks for the help. I got it now.

Matthew Proudman
Matthew Proudman
11,879 Points

when one returns a function unless you tell python what do then a return will just return and nothing with be outputed