patternpythonMinor
Math, Geometry, & Physics Library
Viewed 0 times
physicsmathlibrarygeometry
Problem
I am making a Python program that does math and physics calculations for you. This is my first programming project and is a work in progress. The SymPy library was used for some portion of it.
```
import math
import turtle
import webbrowser
from sympy import *
Planck_constant = 6.626176 * (10 ** -34)
Reduced_Planck_constant = Planck_constant / (2 * math.pi)
x, y, z, t = symbols('x y z t')
def HeronsLaw():
a = float(input("What is the value of A?"))
b = float(input("What is the value of B?"))
c = float(input("What is the value of C?"))
s = (a + b + c) / 2
print s
print "The value above is the value of s."
print math.sqrt(s(s-a)(s-b)*(s-c))
print "The answer above is the area of your triangle."
def PythagoreanTheroemABtoC():
print "The Pythagorean Theroem states that: a^2 + b^2 = c^2."
print "Therefore: c^2 - a^2 = b^2."
print "Therefore: c^2 - b^2 = a^2."
a = float(input("Enter the value of A."))
b = float(input("Enter the value of B."))
c = math.hypot(a,b)
def AreaOfRectangle():
print "The formula for the area of a rectangle is: l x w."
l = float(input("Enter the value of the length."))
w = float(input("Enter the value of the width."))
func4area = l * w
print func4area
print "Above is the area for your rectangle."
def AreaOfSquare():
print "The formula for a area of a square is: l x l."
l = float(input("Please enter your square's length."))
func4area = l * l
print func4area
print "Above is the area for your square."
def PerimeterOfRectangle():
print "The formula for the perimeter for a rectangle is: l + l + w + w."
print "The formula can also be written like this: (l x 2) + (w x 2)."
length = float(input("Please enter the length of your rectangle."))
width = float(input("Please enter the width of your rectangle."))
func4perimeter = (length 2) + (width 2)
print func4perimeter
print "Above is the perimeter of your rectangle."
de
```
import math
import turtle
import webbrowser
from sympy import *
Planck_constant = 6.626176 * (10 ** -34)
Reduced_Planck_constant = Planck_constant / (2 * math.pi)
x, y, z, t = symbols('x y z t')
def HeronsLaw():
a = float(input("What is the value of A?"))
b = float(input("What is the value of B?"))
c = float(input("What is the value of C?"))
s = (a + b + c) / 2
print s
print "The value above is the value of s."
print math.sqrt(s(s-a)(s-b)*(s-c))
print "The answer above is the area of your triangle."
def PythagoreanTheroemABtoC():
print "The Pythagorean Theroem states that: a^2 + b^2 = c^2."
print "Therefore: c^2 - a^2 = b^2."
print "Therefore: c^2 - b^2 = a^2."
a = float(input("Enter the value of A."))
b = float(input("Enter the value of B."))
c = math.hypot(a,b)
def AreaOfRectangle():
print "The formula for the area of a rectangle is: l x w."
l = float(input("Enter the value of the length."))
w = float(input("Enter the value of the width."))
func4area = l * w
print func4area
print "Above is the area for your rectangle."
def AreaOfSquare():
print "The formula for a area of a square is: l x l."
l = float(input("Please enter your square's length."))
func4area = l * l
print func4area
print "Above is the area for your square."
def PerimeterOfRectangle():
print "The formula for the perimeter for a rectangle is: l + l + w + w."
print "The formula can also be written like this: (l x 2) + (w x 2)."
length = float(input("Please enter the length of your rectangle."))
width = float(input("Please enter the width of your rectangle."))
func4perimeter = (length 2) + (width 2)
print func4perimeter
print "Above is the perimeter of your rectangle."
de
Solution
There are a few things that stick out to me Omer:
You should learn the more advanced usage of the
Your constants should be entirely capitalized, e.g.,
Function names should be lower-cased and use underscores (
You should be more consistent with your own style. One one line in a function, you will have something like
Variables should have descriptive names as often as possible. If this means you have trouble with the length of a line know that you can use parentheses and Python will continue evaluating the expression as if it were on one line. This goes for strings, mathematical expressions and other items too. For example, you have:
which could be replaced by
Your
At the end of your file you have a call to
You should learn the more advanced usage of the
print statement (and potentially begin using the print function instead). In may places you have the value of a computation stored in a variable, e.g., var, and you print that and then an explanation. It would be potentially easier for a user to read if you printed it like so:print 'The result of the calculation of var:', varYour constants should be entirely capitalized, e.g.,
PLANCK_CONSTANT = 6.626176 * (10 ** -34)Function names should be lower-cased and use underscores (
_), e.g., def area_of_rectangle():You should be more consistent with your own style. One one line in a function, you will have something like
(a + b + c) / 2 and a line or two later s(s-a)(s-b)*(s-c). This could be helped by using a tool like Flake8 to help you follow the Python community's style guide.Variables should have descriptive names as often as possible. If this means you have trouble with the length of a line know that you can use parentheses and Python will continue evaluating the expression as if it were on one line. This goes for strings, mathematical expressions and other items too. For example, you have:
CM = "If you would like to know definitions in classical mechanics in one dimension enter 1. "which could be replaced by
classical_mechanics = ("If you would like ..."
"... classical mechanics in one dimension enter 1.")Your
if statements do not need parentheses and the community prefers not to use them unless it has to. For example, you currently have: if(ques2 == 8): but the community would write that as if ques2 == 8:At the end of your file you have a call to
Differentiation(). Place that inside the body of an if statement so that it only runs when you do python name_of_your_file.py. The standard way of doing this isif __name__ == '__main__':
Differentiation()Code Snippets
print 'The result of the calculation of var:', varPLANCK_CONSTANT = 6.626176 * (10 ** -34)def area_of_rectangle():CM = "If you would like to know definitions in classical mechanics in one dimension enter 1. "classical_mechanics = ("If you would like ..."
"... classical mechanics in one dimension enter 1.")Context
StackExchange Code Review Q#58912, answer score: 8
Revisions (0)
No revisions yet.