+ 1
What is the differences between my codes?
Can somebody explain how the second code doesn't work in 3 test cases while the first one works perfectly fine? https://code.sololearn.com/cnp2xdKt5dR3/?ref=app
4 odpowiedzi
+ 1
Andrew G
both Quantum and Simon Sauter are right.
in your commented out code, there are indentation errors.
also, replace the if condition from
if menu[buy]:
to
if buy in menu:
+ 2
menu[buy] throws an error when buy is not in menu
+ 2
Because the first code didn't follow the correct syntax for indentation.
+ 1
Sorry for the indentation mistakes, it was just me adding # in my small phone (the initial code was alright, no indentation errors).
Turns out it was the menu[buy]. I remembered I had tried if buy in menu but there was another mistake earlier. Unfortunately when I fixed the mistake, I had changed the if sentence to menu[buy] therefore I added another mistake after fixing one.
Case closed. Thank you! Simon Sauter Quantum Bob_Li