+ 1

How do you calculate an expression in python?

for example how do you calculate 2x+1=3, solve for x. this is what the code should start with expression = input(‘Enter an expression: ’)

15th Apr 2019, 7:44 AM
Bisrat Fekede
Bisrat Fekede - avatar
4 Respostas
+ 8
First, you have to manipulate input string and isolate x in one side. x=(3-1)/2 After that, you could use eval print(eval("(3-1)/2")) >> 1.0
15th Apr 2019, 9:10 AM
Javier Felipe Toribio
Javier Felipe Toribio - avatar
+ 1
for example...?
15th Apr 2019, 8:56 AM
Bisrat Fekede
Bisrat Fekede - avatar
0
i know how to do that, but what i really need is for it to take input from user and calculate that expression.
15th Apr 2019, 9:24 AM
Bisrat Fekede
Bisrat Fekede - avatar
0
it must start like this. expression = input(‘Enter an expression: ’)
15th Apr 2019, 9:25 AM
Bisrat Fekede
Bisrat Fekede - avatar