Skip to content
Advertisement

How to accept input from an enumerated list in Python?

So I have a list that I want to number using enumerate(), then have the user choose an item from the list using the corresponding number. Is there a way to do this?

(This is broken code but hopefully, you get an idea of what I want to do)

JavaScript

Advertisement

Answer

It’s always a good idea to validate user input – especially when you’re expecting numeric values.

If you do that in this case there’s no need to lookup the address after user input because you will already have validated it.

JavaScript

Output:

JavaScript

With invalid user input:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement