-1

Im looking for a way for a user to enter a variable and it recalls the lists information from a specific spot in the list

list = ["0","2","4","8"]

a = input("Enter the list entry you want to retrieve: ")

print (list[a])

if you enter 1 it will print 2, if you enter 2 it will print 4

benvc
  • 14,448
  • 4
  • 33
  • 54
  • 3
    Possible duplicate of [How can I read inputs as numbers?](https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-numbers) – Paritosh Singh Apr 16 '19 at 21:29
  • 2
    `a` is a string, typecast it to an int. – Paritosh Singh Apr 16 '19 at 21:30
  • 1
    As noted by @ParitoshSingh, you need to convert your input to an integer. For example: `int(input("Enter the list entry you want to retrieve: "))`. Also, not usually a good idea to use built-ins like `list` as variable names. – benvc Apr 16 '19 at 21:34
  • 1
    Possible duplicate of [Print value at index given by user input in Python](https://stackoverflow.com/questions/43656179/print-value-at-index-given-by-user-input-in-python) – benvc Apr 16 '19 at 21:46

1 Answers1

1

Convert 'a' to int.

list = ["0","2","4","8"]

a = input("Enter the list entry you want to retrieve: ")

print (list[int(a)])