How do i fix this code. Im trying to pull an item from a list. Have that item mean a word, and pull it by using user input | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do i fix this code. Im trying to pull an item from a list. Have that item mean a word, and pull it by using user input

abc=[1, 2, 3] abc.index([0]) = apple abc.index([1]) = bananna abc.index([2]) = cat if (int(input(''))) = 1 print abc.index(1) elif (int(input(''))) = 0 print abc.index(0)

17th Oct 2018, 4:16 PM
pixel strength
pixel strength - avatar
1 Answer
+ 3
Strings have to be in quotation marks, you use lists (instead of numbers) as list indices, use == instead of = for comparison, end if statements with a colon (:), print() needs brackets in python 3
17th Oct 2018, 5:16 PM
Anna
Anna - avatar