#๐Ÿ”’ help pls asap

11 messages ยท Page 1 of 1 (latest)

nimble emberBOT
#

@olive sand

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

olive sand
#

i was trying to make a for loop that will print a box from the right 5 times and wiould stop the for loop and will continue the while loop skipping the for loop every after while loop when the for loop created the 5 boxes

my code:


import pygame
import sys

pygame.init()


screen = pygame.display.set_mode((640, 480), pygame.RESIZABLE)

clock = pygame.time.Clock()

shapes_color = (0, 0, 0)
screen_color = "white"

blue = (0, 0, 255)
green = (0, 255, 0)
black = (0, 0, 0)
red = (255, 0, 0)
white = (255, 255, 255)

rect_x = 10
rect_y = 400

i = 0

while True:

    screen.fill(screen_color)

    for i in range(6):
        pygame.draw.rect(screen, black, pygame.Rect(rect_x, rect_y, 30, 30), 2)
        rect_x = rect_x + 10
        i = i + 1

        if rect_x == 50:
            rect_x = rect_x - 10
            print("oh no")

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit("EXITED")

    pygame.display.update()
    clock.tick(60)
serene garden
#

Can you clarify what are you trying to do properly?

olive sand
#

nvm i fixed it

#

import pygame
import sys

pygame.init()


screen = pygame.display.set_mode((640, 480), pygame.RESIZABLE)

clock = pygame.time.Clock()

shapes_color = (0, 0, 0)
screen_color = "white"

blue = (0, 0, 255)
green = (0, 255, 0)
black = (0, 0, 0)
red = (255, 0, 0)
white = (255, 255, 255)

while True:

    rect_x = 10
    rect_y = 400

    i = 0

    screen.fill(screen_color)

    for i in range(11):
        if i <= 10:
            pygame.draw.rect(screen, black, pygame.Rect(rect_x, rect_y, 30, 30), 2)
            rect_x = rect_x + 30
            i = i + 1
        elif i >=10:
            break

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit("EXITED")

    pygame.display.update()
    clock.tick(60)
#

thats the new code

#

was stupid of me not to use if statements

olive sand
nimble emberBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

๐Ÿ”’ help pls asap