Is there any way in python to input a condition from user? for example:
import numpy as np
m = np.array([0,1,2,3,4,5])
condition = input() # for example 'm > 50'
print( m [condition])
I want a result of m[m>5] but I want to input this condition from user. Is there any way?
>Solution :
You can do something similar with eval, I think:
x = 5
condition = input('condition: ')
if eval(condition):
print('yes')
And than in input write like x==5 or x>2 etc. and it should work.