假设我想生成数字1,4或7中的一个.
我该怎么做?我原本以为我可以写
import random
rand.randint(1,4,7)
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用.谢谢.
到目前为止,我有一个程序,其中2个玩家可以点击以轮流放置X和O. 我不确定如何让该计划认可赢家/平局.如果你们能帮我制作一个能以任何方式在屏幕上显示胜利/平局的功能,我会永远爱你.谢谢.
from graphics import *
import sys
def player_o(win, center):
'''
Parameters:
- win: the window
'''
outline_width = 5
circle = Circle(center, boxsize/2)
circle.setOutline('red')
circle.setWidth(outline_width)
circle.draw(win)
def player_x(win, p1x, p1y):
'''
Parameters:
- win: the window
'''
for i in range(2):
deltaX = (-1) ** i * (boxsize / 2)
deltaY = (boxsize / 2)
line = Line(Point(p1x - deltaX, p1y - deltaY),
Point(p1x + deltaX, p1y + deltaY))
line.setFill('red')
line.setWidth(5)
line.draw(win)
def game():
global win
global boxsize …Run Code Online (Sandbox Code Playgroud)