#๐ I need help with my homework(don't get my mistake)
26 messages ยท Page 1 of 1 (latest)
@regal plank
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.
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
!code Please post code, not screenshots of code
oh ok
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?
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
what about ```
if len(f)=0
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
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
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.