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

27th Aug 2021, 10:27 AM
Osman Bahadir Yilmaz
Osman Bahadir Yilmaz - avatar
14 odpowiedzi
+ 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
27th Aug 2021, 11:12 AM
Lisa
Lisa - avatar
+ 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
27th Aug 2021, 10:50 AM
Lisa
Lisa - avatar
+ 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!
28th Aug 2021, 11:24 AM
Lisa
Lisa - avatar
+ 1
exponentiation > multiplication, division > addition, subtraction Unless () It's the same in math?
28th Aug 2021, 11:32 AM
Lisa
Lisa - avatar
+ 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.
28th Aug 2021, 12:04 PM
Lisa
Lisa - avatar
+ 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.
28th Aug 2021, 12:13 PM
Lisa
Lisa - avatar
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.
27th Aug 2021, 11:06 AM
Osman Bahadir Yilmaz
Osman Bahadir Yilmaz - avatar
0
Code is added. Plz look at it again?
28th Aug 2021, 10:58 AM
Osman Bahadir Yilmaz
Osman Bahadir Yilmaz - avatar
28th Aug 2021, 10:58 AM
Osman Bahadir Yilmaz
Osman Bahadir Yilmaz - avatar
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
28th Aug 2021, 11:27 AM
Osman Bahadir Yilmaz
Osman Bahadir Yilmaz - avatar
0
In practice it is not working:) look at g2 it is wrong olso
28th Aug 2021, 11:36 AM
Osman Bahadir Yilmaz
Osman Bahadir Yilmaz - avatar
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
28th Aug 2021, 11:59 AM
Osman Bahadir Yilmaz
Osman Bahadir Yilmaz - avatar
0
Ty is there any solution for this confusing situation??
28th Aug 2021, 12:06 PM
Osman Bahadir Yilmaz
Osman Bahadir Yilmaz - avatar