小编Car*_*arm的帖子

知道项目在数组中的位置

纸盘阵列改组后,我想用其下的卡来切换J1的位置。有没有一种方法可以引用J1而不知道它在数组中的位置?谢谢。

import random

deck = ['AC', '2C', '3C', '4C', '5C', '6C', '7C', '8C', '9C', 'TC', 'JC', 'QC', 'KC',
        'AS', '2S', '3S', '4S', '5S', '6S', '7S', '8S', '9S', 'TS', 'JS', 'QS', 'KS',
        'AH', '2H', '3H', '4H', '5H', '6H', '7H', '8H', '9H', 'TH', 'JH', 'QH', 'KH',
        'AD', '2D', '3D', '4D', '5D', '6D', '7D', '8D', '9D', 'TD', 'JD', 'QD', 'KD',
        'J1', 'J2']

# shuffle deck
random.shuffle(deck)

#switch Joker1 with card under it
Run Code Online (Sandbox Code Playgroud)

python arrays shuffle

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

在Python Pygame中使用数组生成行

我试图通过调用数组索引中的点坐标来在Pygame中绘制线条.但是,这会返回错误:

回溯(最近一次调用最后一次):文件"C:/Python33/Games/lineTest.py",第33行,在pygame.draw.line中(windowSurface,BLACK,(0,0),(0,list [j]) ,3)IndexError:列表索引超出范围

这是我的代码:

import pygame, sys, random, time
from pygame.locals import *

# sets up pygame
pygame.init()

# sets up the window
windowSurface = pygame.display.set_mode((500, 500), 0, 32)
pygame.display.set_caption('Line Test')

# sets up the colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)

# draw white background
windowSurface.fill(WHITE)

print('Please enter a number:')
number = input()

# generate random numbers for array
i = 0
list = []
while int(number) > i:
    i = i+1
    x = …
Run Code Online (Sandbox Code Playgroud)

python arrays pygame lines

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

标签 统计

arrays ×2

python ×2

lines ×1

pygame ×1

shuffle ×1