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 (Retired) Pick a Number! Any Number! Imports

Matthew Thompson
Matthew Thompson
3,554 Points

This is driving me crazy. Any help would be amazing.

import random

myList = [1, 2, 3, 4]

def random_num(myList)

return random.randint(1, myList)

I'm banging my head against a wall trying to sort this out.

random_num.py
import random

myList = [1, 2, 3, 4]

def random_num(myList)

  return random.randint(1, myList)
robberbaron
robberbaron
23,869 Points

Just a guess:

return random.choice(myList)

3 Answers

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hola,

You are really close. You have the exact right idea so at least you have the concept. It's a little syntax error. You are forgetting the ':' at the end of your function.

You don't need a list though. That is the only real thing wrong here. The passed in value comes from somewhere else. You don't need to define that.

remove my_list and then add the syntax error : and off you go!

#before
def random_num(myList)

#after
def random_num(myList):

Let me know if that solves your problem or if you have further questions.

Thanks!

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

Your just missing a couple things:

def random_num(myInt):
  return random.randint(1,int(myInt))
Matthew Thompson
Matthew Thompson
3,554 Points

AAAAHHH! Thank you everyone. I am incredibly new and this class really throws in into the deep end quickly. Thank you again and I'm looking forward to learning more.