With the following snippet from a script:
JavaScript
x
7
1
Tile = SelectTile()
2
int(Tile)
3
TileY = Tile
4
TileX = 0
5
#Temporary debug:
6
print("type of tile is: ", type(Tile), "type of TileY is: ", type(TileY))
7
I expected the outcome to be:
JavaScript
1
2
1
type of tile is: <class 'int'> type of TileY is: <class 'int'>
2
but instead I get:
JavaScript
1
2
1
type of tile is: <class 'str'> type of TileY is: <class 'str'>
2
Does anyone know why this is happening and how I can fix it? In case you need it here is SelectTile
:
JavaScript
1
15
15
1
def SelectTile():
2
print("Select Tile to put "O" in:")
3
print("")
4
print(" 1 ॥ 2 ॥ 3 ")
5
print("===॥===॥===")
6
print(" 4 ॥ 5 ॥ 6 ")
7
print("===॥===॥===")
8
print(" 7 ॥ 8 ॥ 9 ")
9
Tile = input()
10
int(Tile)
11
#if Tile != 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9:
12
# print("Invalid Tile! Try again")
13
# SelectTile()
14
return Tile
15
Advertisement
Answer
You are not assigning the new int value to the original variable. Here’s a fix:
JavaScript
1
7
1
Tile = SelectTile()
2
Tile = int(Tile)
3
TileY = Tile
4
TileX = 0
5
#Temporary debug:
6
print("type of tile is: ", type(Tile), "type of TileY is: ", type(TileY))
7