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

Question, Data array A has data series from 1,000,000 to 1 with step size 1...

Data array A has data series from 1,000,000 to 1 with step size 1, which is in perfect decreasing order. Data array B has data series from 1 to 1,000,000, which is in random order.

Programs and data , Programs and Data Object-oriented programming is a...

Programs and Data Object-oriented programming is a popular way  of managing programs, which  groups together data  with  the procedures that  works on them,  thus  facilitatin

Matrix, What are squared matrices?

What are squared matrices?

Expressions and assignment, Expressions and assignment We can think of...

Expressions and assignment We can think of most computer programs as performing some sort of transformation on data.  Our code may get as input the exam scores of everyone in

Variable, from urllib2 import urlopen # Open http://placekitten.com/ for...

from urllib2 import urlopen # Open http://placekitten.com/ for reading on line 4! response = kittens.read() body = response[559:1000] # Add your ''print'' statement here!

List Assignment, Task This problem creates a list containing names. The li...

Task This problem creates a list containing names. The list of names will be printed, sorted, printed again in the new sorted order, written to a new output file, and searched. Ca

Angle between 2 moving line , how to calculate angle between 2 moving line ...

how to calculate angle between 2 moving line in 2d space

Variables, Variables We cannot  go very far without variables. A variabl...

Variables We cannot  go very far without variables. A variable is a value related to a name that we can bind  to have a particular value  and  then  later use in an expression.

#cmdprobs, #Why can''t I cd my Desktop? A minute ago I would open up cmd an...

#Why can''t I cd my Desktop? A minute ago I would open up cmd and it starts in C:\Users\myname but now it''s starting in C:\WINDOWS\system> and I don''t where I am or how to get ou

Range, Range Very frequently, we will want to iterate through a list o...

Range Very frequently, we will want to iterate through a list of integer values, often as indices.  Python gives a useful function, range, which gives lists of integers. It ma

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