+ 2

How can I make this code simple I mean is there any way to code formulas in maths or physics

https://code.sololearn.com/c703tHdrSWw6/?ref=app

21st Sep 2023, 11:28 AM
P A Arrchith Iyer
P A Arrchith Iyer - avatar
6 Answers
+ 4
I'm not exactly sure of your use case but here are a couple of resources you may want to look at: Official Python math module docs: https://docs.python.org/3/library/math.html https://www.google.com/amp/s/www.geeksforgeeks.org/python-math-module
21st Sep 2023, 12:37 PM
Keith
Keith - avatar
+ 3
Your code is correct and that's the actual way to code formula especially pressure and the force being 1D If you need to represent force as a 2D or 3D, then you need to do the same thing but thrice and using the force's value for every axis independently
21st Sep 2023, 2:21 PM
Mirielle
Mirielle - avatar
+ 2
Thank you
21st Sep 2023, 12:43 PM
P A Arrchith Iyer
P A Arrchith Iyer - avatar
+ 2
Instead of a bunch of print calls, I would suggest formatting print like this: print(f'''Code by Arrchith ( N = Newton, Pa = Pascal ) Area = {area} m² Force = {force} N Pressure = {pressure:.2f} Pa ''')
22nd Sep 2023, 12:47 AM
Bob_Li
Bob_Li - avatar
+ 1
Thanks for the tips
22nd Sep 2023, 6:28 PM
Juan-FIdel Ifeanyi Ugweneme
Juan-FIdel Ifeanyi Ugweneme - avatar
0
Write code that is clear and easy to follow, even if it seems less "clever." Code that is too clever can be difficult to maintain and understand.Use consistent indentation and formatting throughout your code. This improves readability and helps identify code blocks.Implement appropriate error handling and validation to handle unexpected input or errors gracefully.Write unit tests to verify the correctness of your code. This ensures that your code functions as expected and allows you to catch and fix errors early.Leverage existing libraries and built-in functions for mathematical or scientific calculations whenever possible. This can simplify your code and reduce the risk of errors.
23rd Sep 2023, 8:08 AM
Mithat