+ 1

Python Program Errors

I am a beginner Python Programmer, In my profile a game called Tic Tac Toe I made to test out my skill or lack of skill. I would ask for insight, tips and corrections to my code. Please copy and paste the code into your IDLE or compiler as the Solo Learn play ground does not handle inputs as well as I like. The code is also here... I also get a error when I press <enter> while in a input. Is there a way around this? Another error is in line 35, i try to reset the list to its base state of "board = ['1', '2', '3', '4', '5', '6', '7', '8', '9']" and it doesn't work. import random, re ''' Name: Elison Crum underscore before variable is a global variable ''' board = ['1', '2', '3', '4', '5', '6', '7', '8', '9'] global _score global _npc_score _score = 0 _npc_score = 0 _name = "Elison" def checkLine(char, spot1, spot2, spot3): if board[spot1] == char and board[spot2] == char and board[spot3] == char: return True def checkAll(char): if checkLine(char, 0, 1, 2): return True if checkLine(char, 3, 4, 5): return True if checkLine(char, 6, 7, 8): return True if checkLine(char, 2, 5, 8): return True if checkLine(char, 1, 4, 7): return True if checkLine(char, 0, 3, 6): return True if checkLine(char, 0, 4, 8): return True if checkLine(char, 2, 4, 6): return True def reset(): board = ['1', '2', '3', '4', '5', '6', '7', '8', '9'] board_render() def board_render(): print(_name + " : " + str(_score) + " NPC : " + str(_npc_score) + "\n") print(" "*5 + board[0] + " | " + board[1] + " | " + board[2]) print(" "*5 + "-"*9) print(" "*5 + board[3] + " | " + board[4] + " | " + board[5]) print(" "*5 + "-"*9) print(" "*5 + board[6] + " | " + board[7] + " | " + board[8] + "\n") def npc_turn(): global _npc_score while True: npc_spot = random.randint(0,8) if board[npc_spot] != 'x': board[npc_spot

5th Nov 2016, 4:08 AM
-- -- --
1 Odpowiedź
+ 2
Hi, I saw your tictactoe code in Python playground. Is it up to date? Board shows nice, but when I tried to play 5 i got Atribute Error it is about spot_input.isalpha() you used. I am not sure what you ment by this, but spot_input is an integer, while isalpha does not seem to be defined neither by you nor is it a pre-programmed method for integers (youare applying method to integer that user entered). If you already changed your code - update it on your python playground as I cannot copy it from your post directly...
7th Nov 2016, 2:22 PM
Chris
Chris - avatar