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

Andy Hitchings
Andy Hitchings
3,351 Points

Hi - what is the answer for this please? I am stuck. Thanks,

Python Basics - code challenge task2/2 - imports.py

5 Answers

Winnie E Tibingana
Winnie E Tibingana
21,066 Points

Hi Andy,

For challenge two please ensure:

  1. The function has to take a list as argument.
  2. Create the list with some data say *my_list *
  3. Create the random numbers using random.randint
  4. Return the number

As shown below:

Ā 

import random
 my_list=[1,2,3]  #thanks for correct Jason
def random_member(my_list):

  random_num = random.randint(0,(len(my_list)-1))
  return my_list[random_num]

Hope this helps

This passes the challenge but it does not seem like it should.

You're reassigning a new list to my_list and losing whatever list was passed in.

import random

def random_num(num):

return random.randint(1, num)

Thank you, Trina.

its not passing

Winnie E Tibingana can't seem to work that code !!

Hi Argzon,

You can post the code you're trying if you're still stuck.

I decided to recheck the challenge.

I'm not sure if the challenge was changed since this question was asked but the instructions no longer match up with the "best answer" here. Post your current code if you still need help. The solution now is different from what Winnie has posted.

Thank you Jason Anello But found the problem and i passed the challenge

Andy Hitchings
Andy Hitchings
3,351 Points

Fantastic - thank you Winnie & Jason