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

challenge task 2 of 3 python basics imports.py

I have been stuck for about 2 days and cannot figure this out is there someone who can help me out with this one please!

imports.py
import random

my_list = [1, 2, 3, 4, 5]
def random_meber(my_list):
  return (random_member)

4 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Fixed a few things:

import random
ā€‹
my_list = [1, 2, 3, 4, 5] #<-- not needed Challenge tester creates input.

def random_member(my_list): #<-- corrected typo in function name
    return len(my_list) #<-- return length of list

ā€‹

thanks Chris appreciate your help with this help out a great deal

thanks

Christopher Miller
Christopher Miller
614 Points

I'm having issues with this one too. Been working at this for a few days now...

I got the 1st line correct, however after that, forget it. I'm unsure how to do this.

What is the return_len doing above?

Again, I still struggle how to know what to do, however if I see the solution, I'm understanding it. However I'm basically just copying someone else's code and not really getting to understand the how and why in order to master Python.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

The return statement is how a function presents a result to send back to the caller. Without the return the function returns a default None which is a Python reserved word meaning "nothing". The format of using return is:

    return some_object

The object some_object is returned to the caller. As a Python short-hand coding style, return can also be used as:

    return some_expression

In this case, the expression some_expression is evaluated and the resulting object is returned. The following two code blocks are equivalent

# block 1
def random_member(my_list):
    result = len(my_list)
    return result

# block 2
def random_member(my_list):
    return len(my_list)

The return_Len is returning the length of the list using the return_Len will return the length of whatever list you may have or have created