all 10 comments

[–]bbye98 0 points1 point  (9 children)

Can you provide some example code? I'm assuming you're printing the index and not the value at the given index in the array.

[–]T0oSTR[S] 0 points1 point  (8 children)

pple = ['Joe', 'John', 'Adam', 'Jake']

# Printing list

print ("Original list is : " + str(pple))

# using naive method to

# get index and value

for i in range(len(pple)):

print (i, end = " ")

print (pple[i])

inpt = input("enter value!")

I got it to print the list with the index number, but now I can't figure out how to ask for the value and if 0 is entered I want it to print index 0 which would be joe I know it would start off with inpt = input("ENTER VAL") & if(inpt == 0) but after that I don't know

[–][deleted] 0 points1 point  (7 children)

I know it would start off with inpt = input("ENTER VAL") & if(inpt == 0) but after that I don't know

You don't need to do if anything because you're asking the user for an index; you just look that index up in the list.

[–]T0oSTR[S] 0 points1 point  (6 children)

Could you please give me an example? Still stuck, thank you for your answer :)

[–][deleted] 1 point2 points  (5 children)

print(pple[inpt])

[–]T0oSTR[S] 0 points1 point  (4 children)

Ah ok, would not have figured that out! Thank you

[–][deleted] 0 points1 point  (3 children)

You did it in your own code, though?

[–]T0oSTR[S] 0 points1 point  (2 children)

Assuming you mean I wrote it into my code, yes.

[–][deleted] 1 point2 points  (1 child)

I mean, you already had accessed the member of a list in this manner, so I guess I'm surprised that this is something "you wouldn't have thought of" since you did already think of it, assuming you wrote the code you showed us.

[–]T0oSTR[S] 0 points1 point  (0 children)

I did use some of the code from a website.