+ 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: ’)
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
+ 1
for example...?
0
i know how to do that, but what i really need is for it to take input from user and calculate that expression.
0
it must start like this.
expression = input(‘Enter an expression: ’)