Common errors and messages, Python Programming

Assignment Help:

Common Errors and Messages

Here are some common Python errors  and error  messages to look  out for. Please let us give if you have any favorite additions for this list.

  • A problem about NoneType often means you forgot a return.

def plus1 (x):

 

x + 1

>>> y = plus1(x)

>>> plus1(x) + 2

Traceback (most recent call last):

File "", line 1, in

TypeError that shows: unsupported operator type(s) for +: 'NoneType' and 'int'

 

  • Weird results from math can give from integer division

>>> 3/ 9

0

  • "Unsubscriptable object" seems you are trying to get an element out of something that isn't a dictionary, list, or tuple.

 

>>> x = 1

>>> x[3]

Traceback (most recent call last):

File "", line 1, in

TypeError that shows: 'int' object is unsubscriptable

 

  • "Object is not callable" defines that you are trying to use something that isn't a procedure or method as if it were.

 

>>> x = 1

>>> x(3)

Traceback (most recent call last):

File "", line 1, in

TypeError that shows: 'int' object is not callable

 

  • "List index out of range" describes that you are trying to read or write an element of a list that is not present.

 

>>> a = range(5)

>>> a

[0, 1, 2, 3, 4]

>>> a[5]

Traceback (most recent call last):

File "", line 1, in

IndexError that shows: list index out of range

 

  • "Maximum recursion depth exceeded" produces the error has a recursive procedure that is nested your parent case is not being reached due to a bug.

 

def fizz(x):

return fizz(x - 1)

>>> fizz(10)

Traceback (most recent call last): File "", line 1, in File "", line 2, in fizz

File "", line 2, in fizz

...

File "", line 2, in fizz

RuntimeError that shows message: maximum recursion depth exceeded

 

  • "Key Error " defines that you are trying to look up an element in a dictionary that is not present.

 

>>> d = {'a':7, 'b':8}

>>> d['c']

Traceback (most recent call last):

File "", line 1, in

KeyError: 'c'

 

 

  • Another common error is forgetting the self before calling a function. This creates the same error that you would get if you tried to call a function that wasn't de?ned at all.

Traceback (most recent call last): File "", line 1, in File "V2.py", line 22, in  

 

add    

return add(v)

NameError: global name 'add' is not defined

 

 


Related Discussions:- Common errors and messages

Procedures, In Python, the fundamental abstraction of a computation is as a...

In Python, the fundamental abstraction of a computation is as a procedure (other  books call them "functions" instead; we will end  up  using  both  values).   A function that  tak

Python programs, Python programs Every  general-purpose computer has a...

Python programs Every  general-purpose computer has a various detailed design, which  defines  that  the way  its program requires  to be specified is different. The "machine

Program to solve word search puzzles, This assignment involves writing a pr...

This assignment involves writing a program to solve word search puzzles. For example in the following word grid it is possible to find the words active, stock, ethernet and java. N

Algorithm, for simple interest and compound interest

for simple interest and compound interest

Common errors and messages, Common Errors and Messages Here are some co...

Common Errors and Messages Here are some common Python errors  and error  messages to look  out for. Please let us give if you have any favorite additions for this list.

Types and declarations, Java programs are  what  is known as statically an...

Java programs are  what  is known as statically and  strongly defined.  Thus,  the  kinds  of all the variables must  be known at the time that the program is written. That seems

Programming, We sell pdf''s from our site and pdfs can be ordered from the ...

We sell pdf''s from our site and pdfs can be ordered from the site by selecting a book, putting it in a shopping cart, then signing in with a password or as a guest, and then check

Perimeter of a polygon, Perimeter of a polygon Now, let's consider the...

Perimeter of a polygon Now, let's consider the problem of computing the length  of the perimeter of a polygon. The input is a structure of vertices,  encoded as a list of list

Data wrangling, http://www.expertsmind.com/questions/data-wrangling-3011642...

http://www.expertsmind.com/questions/data-wrangling-301164244.aspx

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd