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 Basics (2015) Shopping List App Break

What does the "Bummer! maximum recursion depth exceeded" error mean and how can I fix my code?

Every time I try to check my code, an error pops up. It says "Bummer! maximum recursion depth exceeded". I don't know what this means so I don't know what is wrong and what I have to add or change.

breaks.py
def loopy(items):
    # Code goes here
    for items in loopy(items):
      if items == "STOP":
        break
      print(items)

2 Answers

Kourosh Raeen
Kourosh Raeen
23,733 Points

It's because your function is calling itself in line:

for items in loopy(items):

Change your code to:

def loopy(items):
    # Code goes here
    for item in items:
        if item == "STOP":
          break
        else:
          print(item)
Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

In the for loop, loopy(items) is called which recursive runs the loopy function again before continuing, which will call loopy() again in its for loop,.... This run away recursion goes until it hit the maximum recursion depth.

Your code is nearly correct.

def loopy(items):
    # Code goes here
    for item in items:
      if item == "STOP":
        break
      print(item)