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) Letter Game App Even or Odd Loop

Been work on this one for a few. Again without giving the direct answer if possible? Whats wrong with this code?

I plugged this code into my own IDLE and it just kept running until my memory dwindled to zilch. Can you guide me to my issues with out giving me the direct answer?

even.py
import random

start=5 

def even_odd(num):
    # If % 2 is 0, the number is even.
    # Since 0 is falsey, we have to invert it with not.
    return not num % 2

  while start != 0:
    ran_num= random.ranint(1,99)

    if even_odd(ran_num) is True:
      print("{} is even".format(ran_num))

    if even_odd(ran_num) is False:
      print("{} is odd".format(ran_num))

    start-1

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Well the reason it's running forever is because you say start - 1. But that doesn't do anything to adjust the value of the original start value. You have to assign it back into start. You could do something like:

start = start - 1

or

start -= 1

That should at least get your loop to stop running :)

Thanks so much Jen!

Thanks so much Jen!