Python Forum
unsupported operandtype(s) for -: 'list' and 'int'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unsupported operandtype(s) for -: 'list' and 'int'
#1
Here is the basic code.

for a in range(1, 5):
for b in range(0+[a*2]-2],2*a)
print(b)

It shows error unsupported operandtype(s) for -: 'list' and 'int'

I have tried everything, it seems that in the range of second for loop 'a' which is 'int'type becomes 'list'

Please help
Reply
#2
Use paranthesis in calculation. [] operator is used for list

for a in range(1, 5):
 for b in range(0+(a*2)-2,2*a):
  print(b)
Reply
#3
Please use proper code tags while posting your thread. It will be much clearer for us to understand.
So, when you run the code, you have to understand what do you mean by for a in range(1,5):. That basically means all the integers from 1 to 5, excluding 5 itself. Now, you have added another statementfor b in range([0+[a*2]-2],2*a) :. First of all, you should understand that when you type [0+[a*2]-2], python takes that as a list and therefore, the error:
Error:
TypeError: unsupported operand type(s) for +: 'int' and 'list'
So, use the parentheses(), instead of square brackets. The square brackets[] is specifically used in lists
Hope this helps!
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: unsupported opperand type(s) for %: 'int' and 'list' cool_person 7 2,087 May-07-2022, 08:40 AM
Last Post: ibreeden
  unsupported operand type(s) for %: 'list' and 'int' RandomCoder 4 32,700 May-07-2022, 08:07 AM
Last Post: menator01
  please help me TypeError: unsupported operand type(s) for +=: 'int' and 'list' aankrose 2 7,154 Mar-26-2019, 06:00 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020