0
I'm confused why this code isn't working (List question)
I take computing at school (Gcse) and we have some codes to type up and a book the book says this: BUT be careful because if the thing your searching for isn't there you'll get a nasty error. Perhaps try: names = ["Graham", "Eric", "Terry] if "Eric" in names: position = names.index("John") print("Eric in position", position) else: print("Eric not found") I've tried everything I can think of to get the code to work but it just isn't working anyone know what's wrong
5 Answers
+ 4
@Bill Fosam:
It's not a 'semi-colon' ( ; ) but a double quote ( " ) :P
+ 1
Terry"
names.index("Eric")
0
You forgot to close the semi colon for "Terry"
also, since "John" is not in the list, there is no index with "John"
do this:
position = name.index("Eric")
0
Thanks
- 1
REFER THIS CODE:
names = ["Graham", "Eric", "Terry"]
if "Eric" in names:
position = names.index("Eric")
print("Eric in position", position)
else:
print("Eric not found")