0
Writing long mathematical equations
İ m trying to calculate long mathematical equation. But there is a problem. Python acts weird on math operation sequence.for example when u write a**2+2+b*2 , it calculates uncorrectly. So i need to put lots of prantheses"()" to my equation. But that time it is hard to write. İs there any easy way to write long equations? Thank you. In my code only g3 gives me correct solution. But it has lots of prantheses. And hard to write. https://code.sololearn.com/cJBDFW4W0SpY/?ref=app
14 Respuestas
+ 4
Please show the equation. Without seeing we can't solve the problem.
You may break the equation into subequations and but everything together in the end
+ 1
What do you think would be an incorrect calculation?
In my test code it behaves as expected:
https://code.sololearn.com/cuR1erboIz62/?ref=app
+ 1
Python has pretty much the same operator precedence as in maths. So what do you think goes wrong?
Input and output example would be helpful!
+ 1
exponentiation > multiplication, division > addition, subtraction
Unless ()
It's the same in math?
+ 1
In g2 only (R**2) is multiplied by l – the rest of the enumerator is added.
In g3 the complete enumerator is multiplied by l.
+ 1
I don't know what you want to do? Which output do you expect? The code behaves as expected by math and by python.
If you want the counter to be multiplied by l, the parentheses are necessary. If you only want the first term of the enumerator to be multiplied by l, don't use the brackets.
In my example, I removed the denominator and added some space to indicate precedence.
0
İ wrote it randomly. My actual equation is a bit longer. İ mean i don't why but without prantheses every single operation , it gives me wrong answer.
0
Code is added. Plz look at it again?
0
I don't know exactly but i though that python do math operation different order. Maybe first sum 2 numbers then square it. But i m sure that it is very hard to write long equations. And I want to learn easy way like symbolab maybr
0
In practice it is not working:) look at g2 it is wrong olso
0
Yes know it and that's the question. In any calculator g2 and g3 are same but in Python u need to parantese all opereration
0
Ty is there any solution for this confusing situation??