#๐Ÿ”’ Help please!

35 messages ยท Page 1 of 1 (latest)

wicked grail
#

I need to move the "b" to the right then back to the left in a zig zag pattern my code is not letting me do that

white mantleBOT
#

@wicked grail

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.

wicked grail
coarse jetty
#

you could maybe check if t is divisible by 2 and base the spaces off of that
like
z
z
z
z

(idk if i understood what you want correctly)

grave cypress
#

I can see the issue but I would like to know whether you tried debugging using python breakpoint or just print statement?

#

Here you can learn on how to use breakpoint to debug python program in terminal: https://youtu.be/aZJnGOwzHtU?si=6rnG5ESextFnxHTE

Learn how to use the Python Debugger using the breakpoint() function in this Tutorial.

โœ… Write cleaner code with Sourcery: https://sourcery.ai/?utm_source=youtube&utm_campaign=pythonengineer *

๐Ÿš€๐Ÿš€ SUPPORT ME ON PATREON ๐Ÿš€๐Ÿš€
https://www.patreon.com/patrickloeber

๐Ÿš€๐Ÿš€ JOIN MY NEWSLETTE...
โ–ถ Play video
wicked grail
#

bad explanation

#

need to look like this

wicked grail
grave cypress
#

You do not debug only where there is an error, you use it to understand how your current program is behaving in real time.

#

Is it a homework or assignment you are trying to complete? Because it looks like so

coarse jetty
warm knot
#
import time


def zigzag(char, distance, duration):
    if not isinstance(char, str):
        raise TypeError("char must be str")
    if len(char) != 1:
        raise ValueError("char must be of len 1")
    if distance < 0:
        raise ValueError("distance must be not negative")

    elapsed = 0
    i = 0
    switch = False

    while elapsed < duration:
        start = time.perf_counter()
        print(char.rjust(i + 1, " "))

        i = i - 1 if switch else i + 1

        if i == distance or i == 0:
            switch = not switch

        end = time.perf_counter()
        elapsed += end - start


zigzag("B", 10, 1)
wicked grail
#

the hell bro

warm knot
#

takes to long for the bot ๐Ÿ˜‚

wicked grail
#

look i wish i could copy that

#

but i kinda need to understand it ๐Ÿ˜ข

grave cypress
#

@warm knot it looks like an violation of rule no 8

wicked grail
#

@grave cypress do you see problem in my code?

warm knot
#

so you need only to loop throught the amout of spaces

#

and stop the time

#

and switch increasing and decreasing

wicked grail
#

bro when did python get so complicated

grave cypress
# wicked grail <@1346716818408083506> do you see problem in my code?

Yes there is a problem. First you have break your problem into separate parts. First would be to print "B" with increased spaces, such as:

B
 B
  B
   B

Second, once you achieved this, then work on printing "B" in reversed order which will be opposite of the first step, like this:

    B
   B
  B
B

Then last, combine first and second step and repeat it as many times you want

wicked grail
#

oops

#

wasn't the last couple of lines suppoused to do that though?

grave cypress
#

No, first your code inside your loop is not correct. This is why I asked to break your problem into multiple steps because that will help you.

warm knot
# wicked grail bro when did python get so complicated

python is not complicated it is extremly easy, you can not be more simple and easy than python. but that does not make creating a algorithm easier. think about an algorithm has nothing to do with the language. you could do it in pseudocode and implement it in any language

white mantleBOT
#
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.