0

What did i do wrong it fails 2 of the tests

Mathematics Find which math expression matches the answer that you are given, if you have an integer answer, and a list of math expressions. Task: Test each math expression to find the first one that matches the answer that you are given. Input Format: Two inputs: an integer and a space separated string of math expressions. The following operations need to be supported: addition +, subtraction -, multiplication *, division /. An expression can include multiple operations. Output Format: A string that tells the index of the first math expression that matches. If there are no matches, output 'none'. Sample Input: 15 (2+100) (5*3) (14+1) Sample Output: index 1 https://code.sololearn.com/c0Huic0Mu4Uz/?ref=app

28th Sep 2022, 12:27 PM
Costy Game
Costy Game - avatar
1 Answer
+ 4
Costy Game Two or three reasons I can think of: 15 (-5+20) you output none due to: while(a>0){ a/=10; nr++; } another one, "An expression can include multiple operations" means: 15 (3+2+10) again, output none. another thing is that you might need to take into account operators precedence. There might be more... btw choose better and clear names for your variables.
28th Sep 2022, 1:53 PM
Tina
Tina - avatar