Python Math - TypeError NoneType object is not subscriptable

0 votes

I'm making a small program for math (no particular reason, just kind of wanted to) and I ran into the error "TypeError: 'NoneType' object is not subscriptable.

I have never before seen this error, so I have no idea what it means.

import math

print("The format you should consider:")
print str("value 1a")+str(" + ")+str("value 2")+str(" = ")+str("value 3a ")+str("value 4")+str("\n")

print("Do not include the letters in the input, it automatically adds them")

v1 = input("Value 1: ")
v2 = input("Value 2: ")
v3 = input("Value 3: ")
v4 = input("Value 4: ")

lista = [v1, v3]
lista = list.sort(lista)

a = lista[1] - lista[0]

list = [v2, v4]
list = list.sort(list)

b = list[1] = list[0]

print str(a)+str("a")+str(" = ")+str(b)

The error:

Traceback (most recent call last):
  File "C:/Users/Nathan/Documents/Python/New thing", line 16, in <module>
    a = lista[1] - lista[0]
TypeError: 'NoneType' object is not subscriptable
Jan 3, 2023 in Python by erzan
• 630 points

1 answer to this question.

0 votes

“TypeError: 'NoneType' object is not subscriptable” is one of the Python errors does not provide a clear answer for new developers.

What this means is that you are trying to use the subscript (or indexing) operator [] on an object that does not support this operation.

The reason it is referring to NoneType is that the response from File.writelines() is None.

Putting all of this together you are attempting to index into None on the line f.writelines(newline)[cnt].

Changing this line to f.write("\nnow") would resolve the issue ("\n" is the shorthard for newline).

Master the art of Data Science with Python and unlock the power of insights.

answered Jan 4, 2023 by Elton
• 400 points

Related Questions In Python

0 votes
0 answers

TypeError: 'NoneType' object is not iterable in Python

What does this error mean?  I get this ...READ MORE

May 5, 2022 in Python by Kichu
• 19,050 points
0 votes
1 answer

Python TypeError: 'list' object is not callable.

The error says the list is not ...READ MORE

answered Feb 9, 2019 in Python by Omkar
• 69,210 points
0 votes
1 answer

i am normalizing the data set iris in python and get the error ::TypeError: 'numpy.float64' object is not callable

TRY THIS   #Nomalisation for i in names:     print(i)   ...READ MORE

answered Aug 20, 2019 in Python by Noel Deepak Palle
0 votes
1 answer

TypeError: 'Element' object is not subscriptable

Hey Bharti, You can get some idea from ...READ MORE

answered Feb 18, 2020 in Python by Gitika
• 65,910 points
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,060 views
0 votes
1 answer
0 votes
1 answer

Why is `(True, True, True) == True, True, True` not True in Python?

Operator precedence. You're actually checking equality between (True, ...READ MORE

answered Jan 4, 2023 in Python by Elton
• 400 points
0 votes
1 answer

What is the data type of (1) in python?

Typecasting is the process of converting one ...READ MORE

answered Jan 4, 2023 in Python by Elton
• 400 points
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP