Mathematics Code Coach Issues | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Mathematics Code Coach Issues

I can't seem to find the answer to this problem. It fails for unknown test 3-5. Any input would be appreciated. https://code.sololearn.com/ccOP4EmLQZkh/?ref=app

30th Mar 2020, 8:27 PM
DAYLINER BAND
DAYLINER BAND - avatar
11 Answers
+ 2
try this : answer = input() formulas = input().split() found = False for i in formulas: if eval(i) == int(answer): print ("index" , formulas.index(i)) found = True break if not found: print("none")
31st Mar 2020, 9:51 AM
John Robotane
John Robotane - avatar
+ 1
answer = input() formulas = input().split() found = False for i in formulas: if eval(i) == int(answer): out="index " + str(formulas.index(i) ) found = True if not found: out=("none") print (out) This one is completely correct code
19th Jun 2022, 4:34 PM
I am offline
I am offline - avatar
0
I think that you should not remove parentheses.
30th Mar 2020, 9:27 PM
John Robotane
John Robotane - avatar
0
Thanks for the advice. Tried it without removing the parentheses but still does not work.
31st Mar 2020, 1:09 AM
DAYLINER BAND
DAYLINER BAND - avatar
0
does the codecoach ask you to print none? if so maybe print('none') should be out of the for loop.
31st Mar 2020, 6:35 AM
John Robotane
John Robotane - avatar
0
It works for all the "none" test as it is. Here are the instructions for the challenge. 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
31st Mar 2020, 9:37 AM
DAYLINER BAND
DAYLINER BAND - avatar
0
That totally worked! Can you explain to me what the difference between our code is?
31st Mar 2020, 10:01 AM
DAYLINER BAND
DAYLINER BAND - avatar
0
Ohh I think I got it. My code would only work if the correct statement was in the 0 index otherwise I would print none. Thank you so much for the help.
31st Mar 2020, 10:04 AM
DAYLINER BAND
DAYLINER BAND - avatar
0
yes, you got it. thank you too.
31st Mar 2020, 10:08 AM
John Robotane
John Robotane - avatar
0
answ = int(input()) math_expr = input().split() for i in math_expr : if eval(i)==answ: print("index " + str(math_expr.index(i))) break else : print('none')
6th Dec 2021, 8:55 AM
Mas'ud Saleh
Mas'ud Saleh - avatar
0
My solution: score = int(input()) expressions = list(map(eval, input().split(" "))) for x in expressions: if score == x: print("index", expressions.index(x)) break else: print("none")
6th Apr 2022, 12:26 PM
Przemysław Komański
Przemysław Komański - avatar