小编Hei*_*erg的帖子

如何避免多个`elif`语句?

所以,我试图用 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)

python python-3.x

5
推荐指数
1
解决办法
597
查看次数

Django 错误:“您正试图在没有默认值的情况下向条目添加不可为空的字段‘作者’”

在我的 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)

python django model

1
推荐指数
1
解决办法
6472
查看次数

标签 统计

python ×2

django ×1

model ×1

python-3.x ×1