• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Unknown_error [PYTHON]

Status
Not open for further replies.
Level 6
Joined
Oct 10, 2013
Messages
173
So recently I have been making an AI in tic tac toe game.
unfortunately it is giving me headache by this error.

Code:
The current situation of board is...
EMPTY   EMPTY   X

EMPTY   EMPTY   0

EMPTY   EMPTY   EMPTY

The squares starts from 1 to 9.
Which square do you want to move?
9
The current situation of board is...
EMPTY   EMPTY   X

EMPTY   EMPTY   0

EMPTY   EMPTY   X

yes
Traceback (most recent call last):
  File "D:\Softwares\Developing\Python\Installation\programs\TicTacToePractical.py", line 147, in <module>
    board_update(move,computer)
  File "D:\Softwares\Developing\Python\Installation\programs\TicTacToePractical.py", line 67, in board_update
    temp = temp - 1
TypeError: unsupported operand type(s) for -: 'list' and 'int'


The original code of the function
Code:
def board_update(move,player):  #Tested, and disapproved.
    '''Updates the board with respect to input given by the user'''
    temp = move
    global board
    global used
    global X
    global O
    if player == 'X':
        board[move-1] = 'X'
        used = used + [move]
    else:
        temp = temp - 1
        board[temp] = 0
        used = used + [temp]
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
The variable move has been initialized as an into.

Also since temp = move
The variable temp with also be int.
So move -1 gives us an int.

Still I am getting the error

Python:
a = 1
a = "asd"
a = [1, 2, 3, 4]
What is the type of a? Whatever it is set to!

You can be stubborn, or you can actually look at your code and find out why move is a list and not an int...
 
Last edited:
Level 6
Joined
Oct 10, 2013
Messages
173
It was converting int into list unexpectedly!I used the print statement to debug the code.
It printed as follows:
int
int
int
list
Type error

Anyways I solved it,
I used the if else:
Code:
if type(x) == list :
perform list functions
else:
perform integer functions

I don't exactly have the syntax, because it is my rule.I work on a project for atleast 3 days, at fourth day I hands off the job.
 
Status
Not open for further replies.
Top