Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

'hello'[99] 'hello'[4] I made the index between 0 and 4., Study notes of Advanced Computer Programming

SyntaxError: EOL while scanning string literal. SyntaxError: expected an indented block. SyntaxError: invalid syntax.

Typology: Study notes

2021/2022

Uploaded on 09/12/2022

sohail
sohail 🇺🇸

4.5

(16)

236 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Python Error Messages: Gotta Catch em All
New and experienced programmers constantly cause errors. The error messages are often terse, so do a
web search of the message to find out what it means. If you get an error message like
ModuleNotFoundError: No module named 'my_module_name', try doing a web search for the generic
parts of the message like "ModuleNotFoundError: No module named" instead of my_module_name.
For each error you encounter:
1. Check off these error messages below if you havent seen it before.
2. Write down the line of code that caused it (this is given towards the bottom of the error
message).
3. Do a web search of the error message to find out common causes of the error.
4. Write down the code change that fixed the error and/or a short description.
Example:
IndexError: string index out of range
'hello'[99]
'hello'[4] I made the index between 0 and 4.
IndexError: string index out of range
KeyError: 'some_text_here'
ModuleNotFoundError: No module named 'some_text_here'
NameError: name 'some_text_here' is not defined
SyntaxError: can't assign to literal
Version 1, 2019/8/15. https://inventwithpython.com Creative Commons 4.0 BY-NC-SA https://creativecommons.org/licenses/by-nc-sa/4.0/
pf3
pf4

Partial preview of the text

Download 'hello'[99] 'hello'[4] I made the index between 0 and 4. and more Study notes Advanced Computer Programming in PDF only on Docsity!

Python Error Messages: Gotta Catch ‘em All

New and experienced programmers constantly cause errors. The error messages are often terse, so do a web search of the message to find out what it means. If you get an error message like ModuleNotFoundError: No module named 'my_module_name' , try doing a web search for the generic parts of the message like "ModuleNotFoundError: No module named" instead of “my_module_name”.

For each error you encounter:

  1. Check off these error messages below if you haven’t seen it before.
  2. Write down the line of code that caused it (this is given towards the bottom of the error message).
  3. Do a web search of the error message to find out common causes of the error.
  4. Write down the code change that fixed the error and/or a short description.

Example:

✓ IndexError: string index out of range

'hello'[99]

'hello'[4] I made the index between 0 and 4.

IndexError: string index out of range

KeyError: 'some_text_here'

ModuleNotFoundError: No module named 'some_text_here'

NameError: name 'some_text_here' is not defined

SyntaxError: can't assign to literal

Version 1, 2019/8/15. https://inventwithpython.com Creative Commons 4.0 BY-NC-SA https://creativecommons.org/licenses/by-nc-sa/4.0/

SyntaxError: EOL while scanning string literal

SyntaxError: expected an indented block

SyntaxError: invalid syntax

SyntaxError: unexpected indent

TypeError: can only concatenate str (not "int") to str

TypeError: 'str' object is not callable

TypeError: unsupported operand type(s) for +: 'int' and 'str'

ValueError: invalid literal for int() with base 10: 'some_text_here'

ZeroDivisionError: division by zero