0
What am I doing wrong?
I am trying to make a calculator on python, and if I use the '+' symbol, everything executes perfectly. If I dont, it comes up with the error shown below, although according to my code it should say "Try again." Error: Traceback (most recent call last): File "...\Playground\", line 4, in <module> if a.index ("+") ValueError: substring not found https://code.sololearn.com/c0yoGqbZ5fKx/?ref=app
3 Answers
+ 2
use this condition
if "+" in a:
+ 2
From the documentation on str() .index() method.
str.index(sub[,Ā start[,Ā end]])Ā¶
LikeĀ find(), but raiseĀ ValueErrorĀ when the substring is not found.
It will raise a ValueError when the substring isn't found. You need to handle this.
0
ŃŠ°Š¼ ŃŠ°ŠŗŠ¾Š¹