#๐Ÿ”’ simple python question help

11 messages ยท Page 1 of 1 (latest)

tribal compass
#
def squared(string, length):
    row = 0
    while row < length:
        col = 0
        while col < length:
            l = string[(row + col) % len(string)]
            print(l, end="")
            col += 1
        print("")
        row += 1
#row = 0
#col = 0
#l = string[(0 + 0) % 2]
#Repeat for every col with col #+= 1 until it hits length
#Repeat with every row
if name == "main":

    squared("abc", 5)

this is the code i wrote for that question but it doesn't work. I know you can do this by just making a really long string of the word repeated then just iterating over it using slicing to get the output, but just wondering if this can be done using the modulo operator instead, just for my own practice

frigid marlinBOT
#

@tribal compass

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.

tacit fulcrum
tribal compass
tacit fulcrum
# tribal compass yes

so here is how u do this with %, u forget about string for a moment and just try printing the right numbers

#

for "ab", 3" u should try to focus on printing

010
101
010
#

and we do that by having a value that, starting at 0, is always increasing till final square

#

then % 2 that every "step"

tribal compass
#

ic, will try it out and lyk

frigid marlinBOT
#
Python help channel closed for inactivity

This help channel has been closed. 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.