Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Looking for Python code for below problem using functions. ---------------------

ID: 3891431 • Letter: L

Question

Looking for Python code for below problem using functions.

--------------------------------------------------

The Gocargo are automating their testing works of the logistics wing too. They have planned to test if the container loading works correctly or not.
Given the process involved in loading, in the form of expression, evaluate if the container loader has worked correct or not.

Conventions
'{' for cargos, '[' for containers and '(' for boxes.

Rules:
* cargo cannot be inside another cargo or container or box.
* container cannot be inside another container or box.
* box can be inside another box.

Please check whether the container loader has worked correctly.

Sample Input 1 :
{[2+3+4+(2+1)+4+(2+4)]+[3+4]}+{[2+4+5]}
Sample Output 1:
Valid

Sample Input 2 :
{[2+3+4+(2+1)+4+(2+4)]+3+4]}+{[2+4+5]}}
Sample Output 2:
Invalid

Explanation for sample 1:
There are two cargos.
In the first cargo, there are two containers.
          The first container contains two boxes, plus some other items.
          The second container contains no boxes, but two items.
In the second cargo, there is one container with 3 items.
It follows the rules. Therefore, the container loader has worked correctly.

Explanation for sample 2:
The unbalanced brackets shows that the container loader has not worked correctly.

-----------------------------

Thanks

Explanation / Answer

Solution:

GoCargo.py

Sample Run:

{[2+3+4+(2+1)+4+(2+4)]+[3+4]}+{[2+4+5]}
Valid

{[2+3+4+(2+1)+4+(2+4)]+3+4]}+{[2+4+5]}}
Invalid

Note: For any clarification, do comment below before giving any negative feedback. If uou liked the solutioon then don't forget to give a big thumbs up.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote