If the input is a string (ex. 2 + 2 = ), how can I make it to do the operation? I tried using eval, but that doesn't take the =, and also it doesn't print decimals. Also I tried split().
Thank you in advance,
If the input is a string (ex. 2 + 2 = ), how can I make it to do the operation? I tried using eval, but that doesn't take the =, and also it doesn't print decimals. Also I tried split().
Thank you in advance,
You can split at the '+' sign numbers=input.split('+')
, then remove the '=' form the end, secondNumber=numbers.split('=')
. Afther that write
if operator == '+':
output = numbers[0] + secondNumber[0]
print(output)
Or just output=eval(input.split('=')[0])