+ 5
Hi, Why the condition "if" in my code does not work?
I want using "index()", but how should it be? https://code.sololearn.com/cYP9M04qF8Zg/?ref=app
7 Réponses
+ 14
Egor Tonchev(EGO)
If condition works there 🤣
But there is a little problem with your code
If u print your list before for then you will get the problem causing part.💯
this is printed when you print that list [4*3, 12-3 ,3+6 , 40/20']
BUT you need this [ 12,9,9,2]
Soi you can solve it by using eval function 👍 or some other method
+ 6
With the help of all of You I've solved the problem. Special Thanks to Carlos, Swati 🔹 and Calvin Thomas 🙂👍
+ 5
Sω(ᗒ✧ᕙ☞Aᕗ✧ᗕ)ti ,special thanks to
You too
+ 2
'none' is always appeared in tasting.
0
By using eval:
for j in mathact:
if mathres==eval(j):
print("index"+" " +str(mathact.index(j)))
break
elif j==mathact[-1]:
print('none')
0
Egor Tonchev(EGO) You haven't configured the second input:
Use: mathact = input().split()
0
Here's a possible solution:
num = int(input())
arr = input().split()
i = 0
while eval(arr[i]) != num: i += 1
print("index", i)
# Hope this helps