#๐Ÿ”’ While-loops and For-loop.

61 messages ยท Page 1 of 1 (latest)

vagrant thicket
#

Trying to complete my assignments, but for the life of me can't understand while and for-loops.
#1 The first assignment consists of making a 8x8 checkerboard, using only one call to rect (). Using loops.
How can I nest my loops to so I make this?

I'm sure it's easy, but i've just been staring at my screen and getting confused and tired.

I have another assignment, but help with this one will improve my understanding hopefully for the other.

daring hillBOT
#

@vagrant thicket

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.

polar geode
vagrant thicket
#

width = length.............since it's gotta be a quare

#

im doing 25x25

#

and canvas size of 200x200, if that matters. it's mostly just how do i nest the loops

weak wind
#

Here this code uses nested loops to draw an 8x8 checkerboard by calculating each square's position and color based on its row


square_size = 50

for row in range(8):

    for col in range(8):

        x = col * square_size
        y = row * square_size

        if (row + col) % 2 == 0:
            color = 'black'
        else:
            color = 'white'

        rect(x, y, square_size, square_size, color)```
#

I'm not entirely sure if this code is correct but I want to find out.

vagrant thicket
#

๐Ÿ˜ญ where teh while and for loops at

#

oh nvm

weak wind
#

huh?

#

Their inside

daring hillBOT
#

10. Do not copy and paste answers from ChatGPT or similar AI tools.

weak wind
vagrant thicket
#

I just copy pasted it doesn't work.

weak wind
#

I donโ€™t even use chatgpt ๐Ÿ’€

#

Lil bro stop assuming

weak wind
polar geode
#

our goal is to help people learn not give them the answers

vagrant thicket
#

let me show what I have

weak wind
polar geode
vagrant thicket
#

this will be incorrect as I have used call rect() more than once, more than twice even. DeadPepe

polar geode
# weak wind idc

you will, or we will be handing out infractions if this behaviuor of being rude and unhelpful continues. that's not the kind of culture we're trying to foster here

polar geode
weak wind
vagrant thicket
#

a BnW checkerboard

#

but I'm supposed to only use 1-2 call of rect ().

polar geode
#

!mute 1183768582505640010 Take a break and re-read our #code-of-conduct, and listen to moderator instructions

daring hillBOT
#

:incoming_envelope: :ok_hand: applied timeout to @weak wind until <t:1722385716:f> (1 hour).

polar geode
#

anyway

vagrant thicket
#

maybe my take is wrong, idk.

polar geode
#

if im not mistaken?

vagrant thicket
#

noo

polar geode
#

well it seems you're on the right track at least

vagrant thicket
#

the range is of the x and y coordinates

polar geode
#

but instead of going 0, 50, 100, 150, 200 i think you want to instead of 0, 25, 50, ... 200

#

this way you can do it with one call to rect and two loops

vagrant thicket
#

huh

#

think_spin ๐Ÿ˜ญ I'm sorry my brain is kinda exhausted

polar geode
#

its the same thing you have right now but instead of skipping by 50 you skip by 25

#

range(..., ..., 25)

vagrant thicket
#

yeah

#

if I do that for both black n white they wont alternate

#

think_spin or will they, ill try ig

polar geode
#

for alternating you would keep track of some number, and add one each time

#

if its even, color it white, if its odd, color it black

#

or the other way around, doesn't really matter

vagrant thicket
#

ohhh i see...

polar geode
#

there is another, more complex (but pythonic) way to do it i can show you if you're interested but its not necessary

vagrant thicket
#

whar_cat naahh, this is just for uni assignment.

#

gotta keep it to what the teach has asked

polar geode
#

fair enough

daring hillBOT
#
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.