import pygame, sys
pygame.init()
screen = pygame.display.set_mode([800,600])
white = [255, 255, 255]
red = [255, 0, 0]
screen.fill(white)
pygame.display.set_caption("My program")
pygame.display.flip()
background = input("What color would you like?: ")
if background == "red":
screen.fill(red)
running = True
while running:
for i in pygame.event.get():
if i.type == pygame.QUIT:
running = False
pygame.quit()
Run Code Online (Sandbox Code Playgroud)
我试图询问用户他想要什么背景颜色。如果用户写红色,颜色不会改变并且仍然保持白色。
from random import randint\nimport pygame, sys\npygame.init()\nekraan = pygame.display.set_mode([800, 600])\nvalge = [255, 255, 255]\nekraan.fill(valge)\npygame.display.set_caption("\xc3\x9clesanne 6")\npygame.display.flip()\n\n\nv\xc3\xa4rv1 = randint(0, 255)\nv\xc3\xa4rv2 = randint(0, 255)\nv\xc3\xa4rv3 = randint(0, 255)\nasukoht_x = randint(0, 800)\nasukoht_y = randint(0, 600)\nsuurus = randint(5, 100)\n\ni = 1\nfor i in range(100):\n pygame.draw.circle(ekraan, (v\xc3\xa4rv1, v\xc3\xa4rv2, v\xc3\xa4rv3), [asukoht_x, asukoht_y], suurus, 0) \n pygame.display.flip()\n i = i + 1\n\n\n\nrunning = True\nwhile running:\n for i in pygame.event.get():\n if i.type == pygame.QUIT:\n running = False\n pygame.quit()\nRun Code Online (Sandbox Code Playgroud)\n\n我试图让程序绘制 100 个圆圈,每个圆圈都有随机颜色、随机 X、Y 坐标和随机大小。我正在使用 for i in range(100) 但它不起作用。该程序仅绘制 1 个圆圈,其中一切都是随机的。 …