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

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.