What is the differences between my codes? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

17th May 2022, 10:25 AM
Andrew G
4 Answers
+ 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:
17th May 2022, 10:53 AM
Bob_Li
Bob_Li - avatar
+ 2
menu[buy] throws an error when buy is not in menu
17th May 2022, 10:43 AM
Simon Sauter
Simon Sauter - avatar
+ 2
Because the first code didn't follow the correct syntax for indentation.
17th May 2022, 10:43 AM
Jan
Jan - avatar
+ 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
17th May 2022, 11:00 AM
Andrew G