The error message cut of the script | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

The error message cut of the script

If the script is the following: letters = ['p', 'q', 'r', 's', 'p', 'u'] print(letters.index('r')) print(letters.index('n')) print(letters.index('s')) The output is 2 Traceback (most recent call last): File "./Playground/file0.py", line 3, in <module> print(letters.index('n')) ValueError: 'n' is not in list But.. there is no answer for the third line. Why? Does the error command imply that the next line is not executed?

14th Jan 2020, 3:31 PM
Julia Lo Medico
Julia Lo Medico - avatar
4 Answers
+ 1
something like: letters = ['p', 'q', 'r', 's', 'p', 'u'] print(letters.index('r')) try: print(letters.index('n')) except ValueError: print("does not exist") print(letters.index('s'))
14th Jan 2020, 3:48 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 2
since n does not exist it throws an exception. if you want to continue to the third print. handle the ValueError exception.
14th Jan 2020, 3:38 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 2
There is an answer for the 3rd line, it does tell you that ValueError: 'n' is not in list. When the python parser found an error, it stops the rest of the script's execution, so you must catch the error, with a try catch block.
14th Jan 2020, 3:43 PM
Calin Onofrei
Calin Onofrei - avatar
+ 1
If the error isn't handled the script won't continue executing
23rd Jan 2020, 12:46 AM
Esteban Rigoni
Esteban Rigoni - avatar