Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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