Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

Nicholas Anstis
Nicholas Anstis
2,095 Points

A question for enumeration on command (Python)

I have this code in there https://w.trhou.se/5d36o6f9ai and i don't know why it doesn't print out my function whenever I type 'call'

Hope you can help me

4 Answers

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello Nicholas,

You have defined the function, but the function is never invoked. If you want to invoke the function you could do so like this.

def alpha():

    if say == call:
        alpha()

    for step in enumerate(my_alpha):
        print('{}: {}'.format(*step))

my_alpha = list('abcdefghijklmnopqrstuvwxyz')
call = 'call'
say = int(input("Say smthin "))
alpha();

I hope this helps.

Nicholas Anstis
Nicholas Anstis
2,095 Points

Uhm, Thanks for taking time to reply but I still get this ValueError for the Call variable

Whenever i type call into the shell I wish it could give me the alpha_list back. BUt instead i get a ValueError.

Hope you can help me :p

Justin Horner
Justin Horner
Treehouse Guest Teacher

Ah, that's because you're trying to cast the string coming from the input method to an int.

say = int(input("Say smthin "))

Input will always return a string and if you type 'call' for the input, it will attempt to cast that to an integer and fail.

I'm not sure what you want the program to do, but if you type 'call' for the input, you're going to end up with a RecursionError because the alpha function will recursively call itself, since there's no loop to change the value of the say variable.