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


Not sure why list isn't as long as it should be

I'm trying to generate a list of questions, but for some reason my list only returns length 2. Any idea why it's not appending all 10?

import random

from questions import Add, Multiply

questions = []

for num in (1,10):
  type = random.randint(1,2)
  if type == 1:
    newquestion = Add(random.randint(1,10), random.randint(1,10))
  elif type == 2:
    newquestion = Multiply(random.randint(1,10), random.randint(1,10))


1 Answer

Hanley Chan
Hanley Chan
27,771 Points


It looks like you are only looping through your for loop twice instead of ten times.

It should loop through 10 times if you use:

for num in range(0,10):
  # rest of code here

Thanks, completely blanked on that part of the syntax.