Joshua Aranda
Joshua Aranda

Reputation: 11

How to index a list based on user input, and print the result

Here is what i am trying to do.. I want the user to pick a number, and then print word from my list that the number indexes. This is what i have so far

mylist = ["john","jack","jen","judy","jill"]
mylist
add = input("please state a name")
mylist.append(add)
print (mylist)
add = input("please state a number")

Upvotes: 1

Views: 16792

Answers (1)

spg
spg

Reputation: 9837

This would work:

index = input("please state a number")
index = int(index)
name = mylist[index]
print(name)

Upvotes: 1

Related Questions