How to make this code work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to make this code work?

https://sololearn.com/compiler-playground/cQfKH3oguuj7/?ref=app Sample usage #1: >>> l = LinkedList([2, 7, 4, 9, 18, 19, 22]) >>> l.to_list() [2, 7, 4, 9, 18, 19, 22] >>> l.len() 7 >>> l.get(3) 9 >>> l.has(17) False >>> o = LinkedList([7]) >>> o.to_list() [7] >>> o.len() 1 >>> e = LinkedList([]) >>> e.to_list() [] >>> e.len() 0 Sample usage #2: >>> l = LinkedList([2, 7, 6, 4]) >>> l.delete(2) >>> l.delete(5) >>> l.delete(4) >>> l.to_list() [7, 6] >>> l.delete(6) >>> l.delete(7) >>> l.to_list() [] >>> l.delete(8) >>> l.to_list() [] Sample usage #3: >>> l = LinkedList([2, 7, 4]) >>> l.rotate() >>> l.to_list() [4, 2, 7] >>> o = LinkedList([8]) >>> o.rotate() >>> o.to_list() [8] >>> e = LinkedList([]) >>> e.rotate() >>> e.to_list() [] Sample usage #4: >>> l = LinkedList([2, 7, 4, 9, 18, 19, 22]) >>> m = LinkedList([2, 7, 4]) >>> n = LinkedList([9, 18, 19]) >>> e = LinkedList([]) >>> l.starts_with(m) True >>> m.starts_with(l) False >>> l.starts_with(e) True >>> l.contains(n) True >>> m.contains(l) False

18th Feb 2024, 4:14 AM
safir safir1
safir safir1 - avatar
6 Answers
+ 2
init is a dunder method. def __init__(self, ...): not def init(self,...):
18th Feb 2024, 5:36 AM
Bob_Li
Bob_Li - avatar
+ 2
Bob_Li , I mentioned init vs __init__ in his last thread. Maybe he didn't see it. I get the impression that his teacher avoids dunders, because most of the other required methods should really be implemented as some combination of dunders too, but __init__ is unavoidable.
18th Feb 2024, 7:21 AM
Rain
Rain - avatar
+ 1
safir safir1 , Thanks for providing the playground link, but why did you start a new thread? https://www.sololearn.com/Discuss/3265678/?ref=app
18th Feb 2024, 7:11 AM
Rain
Rain - avatar
+ 1
safir safir1 , What about the usage examples in this opening message? Are those from a session with your teacher's completed solution (since yours doesn't work yet)? .rotate() and .startswith() were not described in the requirements in your previous thread. Sololearn doesn't have an interactive Python Read, Evaluate, Print, Loop (REPL) terminal mode. You'll have to write the usage into your code as executable statements and run it normally. You can use this Python idiom to make the file both runnable and importable: # Your classes go here. class Node: pass class LinkedList: pass def main(): # Your test usage stuff goes here. pass if __name__ == "__main__": # Only call main() if this module (file) # is run, not if it is imported. main()
18th Feb 2024, 7:31 AM
Rain
Rain - avatar
+ 1
Thanks Rain, I am fixing code
18th Feb 2024, 7:33 AM
safir safir1
safir safir1 - avatar
0
d>
20th Feb 2024, 3:21 AM
Seema Kasera
Seema Kasera - avatar