#๐Ÿ”’ I need help with my homework(don't get my mistake)

26 messages ยท Page 1 of 1 (latest)

regal plank
#

#queue function

sterile eagleBOT
#

@regal plank

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.

regal plank
#

Write a signature function scroll(f: ([int], [int])) -> int that returns the value of the element at the head of the queue (i.e. the oldest) and removes it from the queue. If the queue is empty nothing is returned

#

i wrote this

#

i don't understand my mistake

frigid pilot
#

!code Please post code, not screenshots of code

sterile eagleBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

regal plank
#

oh ok

frigid pilot
#

anyway the problem with if not f[0] is that empty lists/tuples/strings are considered Falsy in Python

#

so that if statement gets executed if f[0] is present but is an empty list (which I guess you don't want?)

#

in the function, is f the queue?

regal plank
#

yes

#

is ``

frigid pilot
#

so to test if f is empty, you should just do if not f.

#

if not f[0] tests the zeroth element of f, it doesn't test f itself

regal plank
#

what about ```
if len(f)=0

frigid pilot
#

to compare values you use ==, not =

#

other than that, this also works to test for an empty list. although usually in Python we just write if not f as its shorter

regal plank
#

oh okay

#

thanks

regal plank
#
def defiler(f):
    if f[1]:
        g=f[1].pop()
        return g
    elif f[0]:
        e=f[0].pop(0)
        return e
    else:
        return None
#

return values are OK but it says incorrect side effect on arguments

sterile eagleBOT
#
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.