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

6th May 2017, 6:07 PM
Olivia
5 Answers
+ 4
@Bill Fosam: It's not a 'semi-colon' ( ; ) but a double quote ( " ) :P
7th May 2017, 12:51 AM
visph
visph - avatar
+ 1
Terry" names.index("Eric")
6th May 2017, 6:21 PM
黄攷
黄攷 - avatar
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")
6th May 2017, 6:25 PM
Bill Fosam
Bill Fosam - avatar
0
Thanks
6th May 2017, 6:32 PM
Olivia
- 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")
12th May 2017, 10:12 AM
Kavin Kumar
Kavin Kumar - avatar