Queue & dequeued | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Queue & dequeued

This is in python language. I need to debug this project I have been working on. The first goal is to run test cases, but my code failed each test case. Do you think it is a good idea to call the test case from... class Priority_Queue: to print("Test 1") P1 = Priority_Queue() P1.enqueue(2,10) P1.enqueue(5,50) print(P1) Let me know if you can view the project here. https://www.sololearn.com/compiler-playground/cFP26KuV2izp

3rd Feb 2023, 12:11 AM
Chris
Chris - avatar
7 Respostas
+ 1
No problem ... Actually, you can opt not use the arguments' indices, but if you omit the indices, the arguments must be given in correct sequence / order. Where if you use the indices, you have the freedom to arrange where an argument was to be placed in the formatted string returned by format() print( "{} {}".format( "Cat", 101 ) ) print( "{1} {0}".format( "Cat", 101 ) ) Try those lines to see that use of the indices altered how the arguments are placed in the string returned by format() You cannot however, mix the two approach. Like having a {} and {<index>} together.
4th Feb 2023, 8:41 AM
Ipang
+ 3
Don't know about test cases But the error you spoke about was because you missed argument index for the priority field Line 27 return "{0} (Pri:{1})".format(self.value, self.priority)
3rd Feb 2023, 8:06 AM
Ipang
+ 2
In code coaches, you don't need to add test cases.. Read task description and implement the task. If need accept input. And code is executed with test cases automatically when you run the code.. And your output should match with expected output exactly...
3rd Feb 2023, 8:07 AM
Jayakrishna šŸ‡®šŸ‡³
+ 1
What does it mean I missed argument index for priority field? Do I need to add value, priority only and remove self?
3rd Feb 2023, 3:43 PM
Chris
Chris - avatar
+ 1
Look at line 27 again, and compare it with the corrected format string I suggested earlier ... return "{0} (Pri:{1})".format(self.value, self.priority) The {0} and the {1} represent the zero-based index of argument(s) given to format() method 1st argument (index 0) is self.value field 2nd argument (index 1) is self.priority field Nothing to add, except you were passing more than those two fields as format() arguments. I meant to note that you forgot {1} in the format string, that's all ...
3rd Feb 2023, 5:27 PM
Ipang
+ 1
Thank you! When I originally started this process, I added "The {0} and the {1} represent the zero-based index of argument(s) given to format() method" but I felt like it was wrong at the time. This could have saved me so much time if I stuck with my first impression.
4th Feb 2023, 4:45 AM
Chris
Chris - avatar
0
I do have a question about this similar code. I need to figure out how to make it return the full-string representation of a person in the queue. https://www.sololearn.com/compiler-playground/cT4xGAck6EQu
6th Feb 2023, 3:18 AM
Chris
Chris - avatar