所以,我试图用 python 制作一个基本的 Tic-Tac-Toe 游戏,我创建了一个运行良好的游戏,但我的代码不是那么好,因为它有很多用于检查列表索引的代码(Winner Of游戏),这有点困扰我。那么,我如何避免使用左索引来检查游戏的获胜者?
我的代码:
board = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
def show_board():# for showing the tic-tac-toe board
print(' | ' + str(board[0]) + ' | ' +
str(board[1]) + ' | ' + str(board[2]) + ' | ')
print(' | ' + str(board[3]) + ' | ' +
str(board[4]) + ' | ' + str(board[5]) + ' | ')
print(' | ' + …Run Code Online (Sandbox Code Playgroud) 在我的 models.py 文件中添加了一个 author 字段后,我试图进行迁移,但 Django 问我这个:
You are trying to add a non-nullable field 'author' to entry without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
2) Quit, and let me add a default in models.py
Run Code Online (Sandbox Code Playgroud)
我的 Models.py 文件:
from django.db import models
from django.utils import timezone
from django.urls …Run Code Online (Sandbox Code Playgroud)