Nowy kurs! Każdy programista powinien nauczyć się Generative AI!
Wypróbuj darmową lekcję0
Hi everyone .
I have two problems here the first one: why does not keyerror’s except work here despite of typing items which is not exsit the second when I click control d nothing happens and what the purpose of eof here? https://www.sololearn.com/en/compiler-playground/cQk7Y03Eolnq
2 odpowiedzi
+ 1
KeyError exception is not raised (triggered) because there is that `if` conditional at line 20 which prevents the attempt to refer a dictionary item from <menu> dictionary at line 21.
The `if` conditional at line 20 checks whether there is an item having <order> as its key in <menu> dictionary. If such item exists, its value will be added into <cost>. If you omit the check at line 20 and just go ahead try to accumulate the cost, you will have KeyError raised when <order> contains invalid key.
Where did you use "control d"? such key combination only works in real console interface. It won't work on SoloLearn.
0
ThaksIpang actually I have tried the code on sololearn.
Do you mean if statement prevents
implementing key error's except.