0
Can I use variables to take users input as index for a Python list ?
9 Réponses
+ 2
malbar3353
I think Slick meant;
choice = int(input("Enter a number (1-5): ")) - 1
+ 2
Thanks Slick and ChaoticDawg it worked🥳🥳🥳 I learned a new thing today !
+ 1
Yes ChaoticDawg, thanks
0
a = ['a', 'e', 'i', 'o', 'u']
choice = int("Enter a number (1-4): ") - 1
print("You chose:", a[choice])
# input
Enter a number (1-4): 2
#output
You chose: e
0
Slick apparently your code seems not to be working I've got an error message : "invalid literal for int() with base 10 : 'enter a number (1-4):'"
0
Yeah, you have to enter a number!
0
The input doesn't include the prompt. I added that cause that's what you'd see and i thought it'd help a bit
0
✌✌