此代码输出 00000000,但我认为它会输出 00000011,因为最后 2 个索引符合 if 条件。
import pygame
numbers = [pygame.Color("#FFFFFF"),
pygame.Color("#FFFFFF"),
pygame.Color("#FFFFFF"),
pygame.Color("#FFFFFF"),
pygame.Color("#FFFFFF"),
pygame.Color("#FFFFFF"),
pygame.Color("#FF0000"),
pygame.Color("#FF0000")]
x = 0
binary = ""
for number in numbers:
print(number)
if numbers[x] == pygame.Color("#FF0000"):
binary += "1"
elif numbers[x] == pygame.Color("#FFFFFF"):
binary += "0"
print("after: ", binary)
沧海一幻觉
慕哥9229398
相关分类