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."
def PermimeterOfSquare():
print "The formula for the perimeter of a square is: l x 4."
print "You could also write the formula as: l + l + l + l."
a = float(input("Please enter the length of your square."))
func4perimeter = a * 4
print func4perimeter
print "Above is the perimeter of your square."
def VolumeforCube():
print "The formula for the volume for a cube is: l * w * h."
a = float(input("Please enter the length of yone face of your cube."))
b = float(input("Please enter the width of one face of your cube."))
c = float(input("Please enter the height of your cube."))
func4volume = a * b * c
print func4volume
print "Above is the volume for your cube. Don't forget the units: cm cubed."
def AreaOfATriangle():
print "The area of a triangle if given height and base is: 1/2 x b x h or b x h / 2"
a = float(input("Please enter the height of your triangle."))
b = float(input("Please enter the base of your triangle."))
func4area = (a * b) / 2
print func4area
print "Above is the area for your triangle."
def AreaOfACircleRadiusOnly():
print "The formula for the area of a circle is : radius squared x pi"
a = float(input("Enter the value of your radius."))
funca = a * a
func4area = math.pi * funca
print func4area
print "Above is the area of your circle. Only round the area to three or two decimal places."
def AreaOfACircleDiameterOnly():
a = float(input("Enter the value of your diameter."))
func4radius = a / 2
func4area = func4radius * math.pi
print func4area
print "Above is the area of your circle. Only round to two or three decimal places."
def AreaOfCircleCircumferenceOnly():
a = float(input("Enter the value of your circle's circumference."))
func4diameter = a / math.pi
func4radius = func4diameter / 2
func4area = func4radius * math.pi
print func4area
print "Above is the area of your circle. Only round to two or three decimal places."
def CircumferenceOfACircleDiameterOnly():
a = float(input("Enter the value of your diameter."))
func4circumference = a * math.pi
print func4circumference
def CircumferenceOfACircleRadiusOnly():
a = float(input("Enter the value of your radius."))
func4diameter = a * 2
func4circumference = func4diameter * math.pi
print func4circumference
def CircumferenceOfACircleAreaOnly():
a = float(input("Enter the value of your area."))
func4radius = math.sqrt((a/math.pi))
func4diameter = func4radius * 2
func4circumference = func4diameter * math.pi
print func4circumference
def AnglesOnALine():
a = float(input("What is the value of one angle on your line besides the given angle?"))
step1 = a + 90
step2 = 180 - step1
print step2
print "The value above is the value of the x angle."
def TangentFunction():
x = float(input("Enter the value of the angle whose tangent you would like to find out."))
a = math.degrees(math.tan(x))
print a
print "Above is the value of the tangent of your chosen angle in degrees."
def CosineFunction():
x = float(input("Enter the value of the angle whose cosine you would like to find out."))
a = math.degrees(math.cos(x))
print a
print "Above is the value of the cosine of your chosen angle in degrees."
def SineFunction():
x = float(input("Enter the value of the angle whose sine you would like to find out."))
a = math.degrees(math.sin(x))
print a
def RaisingNumbersToAnyPower():
x = float(input("Enter the value of your number."))
y = float(input("Enter the value of the power you would like to calculate of that number."))
a = math.pow(x,y)
print a
def LogarithmOfANumber():
x = float(input("Enter the value of the base you are going to be using."))
y = float(input("Enter the value of the number you want to find the logarithm of."))
a = math.log(y,x)
print a
def RadianToDegrees():
x = float(input("Enter the value of your angle in radians"))
print math.degrees(x)
print "Above is the value of your angle from radians to degrees."
def DegreesToRadians():
x = float(input("Enter the value of your angle in degrees. "))
print math.radians(x)
print "Above is the value of your angle in radians"
def EToPowers():
x = float(input("Enter the value of the power you would like to calculate e to."))
epow = pow(math.e, x)
print epow
def PiToPowers():
x = float(input("Enter the value of the power you would like to calculate pi to."))
pipow = pow(math.pi, x)
print pipow
def Averages():
divisor = float(input("How many values do you have?"))
print "This function is going to give you averages. If you only have say 2 values then just enter 0 on the boxes after 2."
a = float(input("Enter your first value."))
b = float(input("Enter your second value."))
c = float(input("Enter your third value."))
d = float(input("Enter your fourth value."))
e = float(input("Enter your fifth value."))
f = float(input("Enter your sixth value."))
g = float(input("Enter your seventh value."))
h = float(input("Enter your eighth value."))
i = float(input("Enter your ninth value."))
j = float(input("Enter your tenth value."))
k = float(input("Enter your elevnth value."))
avg = (a + b + c + d + e + f + g + h + i + j + k) / divisor
print avg
print "Above is the value of your average"
def ArcTan():
x = float(input("Enter the value of the angle you would like to calculate the arc tangent of. "))
a = math.degrees(math.atan(x))
print a
def ArcCos():
x = float(input("Enter the value of the angle you would like to calculate the arc cosine of. "))
a = math.degrees(math.acos(x))
print a
def ArcSine():
x = float(input("Enter the value of the angle you would like to calculate the arc sine of. "))
a = math.degres(math.asin(x))
print a
def PrimeNumberFinder():
x = float(input("Enter the value any integer you want."))
a = 2 ** x - 1
print str(a) + ". Here is the value of your prime number."
if (0):
print "Nice try, troll."
def Force():
a = float(input("If acceleration and mass is given, enter 0. If change in momentum is given, enter 1. "))
if (a == 0):
Intro = "The force will be calculated using mass and acceleration."
print Intro
mass = float(input("Enter the mass of your object. "))
acceleration = float(input("Enter the acceleration of your object. "))
force = mass * acceleration
print str(force) + " N"
if (a == 1):
Intro = "The force will be calculated using change in momentum and time. "
print Intro
change_in_momentum = float(input("Enter the change in momentum of your object. "))
time = float(input("Enter the time."))
force = change_in_momentum / time
print str(force) + " N"
def Displacement():
a = float(input("I you have average velocity enter 0. If you have velocity enter 1. Else enter 2. "))
if (a == 0):
print "Your displacement will be calculated using your average velocity and time."
v_avg = float(input("Enter your average velocity. "))
time = float(input("Enter your time. "))
displacement = v_avg * time
print str(displacement) + " m"
if (a == 2):
print "Your displacement will be calculated using the standard method."
v_i = float(input("Enter your initial velocity. "))
a = float(input("Enter your constant acceleration. "))
t = float(input("Enter your time. "))
displacement = v_i * t + 1/2 * a * t ** 2
print str(displacement) + " m"
if (a == 1):
v = float(input("Enter your velocity. "))
time = float(input("Enter your time. "))
displacement = v * time
print str(displacement) + " m"
def Formula_Sheet():
webbrowser.open('lol')
def Gradient():
delta_y = float(input("Enter your change in y axis value. "))
delta_x = float(input("Enter your change in x axis value. "))
gradient = delta_y / delta_x
print gradient
def Integral_power_rule_one_order():
a = float(input("Enter the highest bound that you are integrating from. "))
b = float(input("Enter the lowest bound that you are integrating from. "))
a_b = ((a**3)/3)-((b**3)/3)
print str(a_b) + " units^2"
def Definitions():
CM = "If you would like to know definitions in classical mechanics in one dimension enter 1. "
TD = "If you would like to know definitions in thermondynamics enter 2. "
EM = "If you would like to know definitions in electricity and magnetism enter 3. "
WM = "If you would like to know definitions in waves enter 4. "
FS = "If you would like to see the formulas please enter 5."
a = float(input(CM + TD + EM + WM))
if(a == 1):
a = "For vectors and scalars enter 1. "
b = "For velocity, acceleration and displacement enter 2. "
c = "For force, momentum, impulse and Newton's laws enter 3. "
d = "For work, energy, power enter 4. "
Q1 = float(input(a + b + c + d))
if(Q1 == 1):
print "Vector and scalars are types of things. In classical mechanics anything that you come across is either a vector or scalar. "
print "A vector has a direction and a magnitude, a magnitude is size or amount. An example of a vector is velocity. Velocity has a direction and it has a size. "
print "Vectors are often denoted with an arrow on top or being bold. "
print "A scalar only has a magnitude. It has no direction. An example of a scalar is speed. It only has a magnitude. "
if(Q1 == 2):
print "Velocity is a vector. It has a direction and a magnitude. Velocity is how fast something is travelling in a certain direction. "
print "When talking about vectors you have to specify which direction you are talking about. People usually use east, west, north and south. Instead you can use the minus and positive sign. You have to specify if minus is up, down, left or right if you chose this notation. "
print "Acceleration is the rate of change of velocity over a certain peroid of time. Acceleration can be constant and non constant. "
print "Displacement is the linear distance in a certain direction. Simply put it is how far you are from your original starting position. "
print "If velocity is constant then there is no acceleration. If velocity is non constant then there is acceleartion present."
print "The relations between velocity, acceleration and displacement is expressed in differential calculus. The derivative of displacement is velocity. The second derivative of displacement is acceleration. "
print "If an object is dropped off from a large height then the air resistance which will act upon it will be affecting it's velocity drastically. If dropped of a small height then it's air resistance is negligable"
print "The acceleration that obejcts experience when they are thrown is called the accleration due to gravity. This accelartion only acts vertically. "
if(Q1 == 3):
print "Force is a push, pull or twist. Forces can either be unbalanced or balanced. Balanced forces either result in no motion or constant motion. Unbalanced forces result in non constant motion. An example of a balanced force is a team in tug-of-war who are stationary. Or when a car is moving at a constant speed."
print "When a car moves at a constant speed it means all the forces acting upon it are balanced."
print "There is a type of force which acts in the opposite direction. It opposes an objects motion. This type of force is called a resistive force. Forces which are resistive forces are: air resistance, friction and water resistance."
print "Terminal velocity is when air resistance and the force of gravity are completely balanced. This results in your velocity being constant. "
print "Air resistance depends on the surface area and the shape of the body. "
print "Friction is a force that causes heat. Friction can be decreased by applying a lubricant. This way there is less heat so therefore there is less friction. "
def Differentiation():
ques1 = float(input("If you would like to do trigonometry enter 1, if power rule, enter 2, if chain rule enter 3, if simple arithmetic enter 4, if exponentials and logs enter 5. "))
if(ques1 == 2):
a = float(input("Enter what power you are going to be differentaiting to. "))
b = float(input("Enter the coefficent of your x. "))
result_1 = diff(b*x**a , x)
print result_1
if(ques1 == 1):
ques2 = float(input("If you need to differentiate sin enter 1, cos enter 2, tan enter 3, arcsin enter 4, arccos enter 5, arctan enter 6, csc enter 7, cot enter 8, sec enter 9. "))
if(ques2 == 1):
b = float(input("Enter the coefficent of your sine. "))
result_1 = diff(b*sin(x), x)
print result_1
if(ques2 == 2):
b = float(input("Enter the coefficent of your cosine. "))
result_2 = diff(b*cos(x), x)
print result_2
if(ques2 == 3):
b = float(input("Enter the coefficent of your tangent. "))
result_3 = diff(b*tan(x), x)
print result_3
if(ques2 == 4):
b = float(input("Enter the coefficent of your arc-sine. "))
a = b*(sin(x)**-1)
result_4 = diff(a, x)
print result_4
if(ques2 == 5):
b = float(input("Enter the coefficent of your arc-cosine. "))
a = b*(cos(x)**-1)
result_5 = diff(a , x)
print result_5
if(ques2 == 6):
b = float(input("Enter the coefficent of your arc-tangent. "))
a = b*(tan(x)**-1)
result_6 = diff(a, x)
print result_6
if(ques2 == 7):
b = float(input("Enter the coefficent of your cosecant. "))
result_7 = diff(b*csc(x), x)
print result_7
if(ques2 == 8):
b = float(input("Enter the coefficent of your secant. "))
result_8 = diff(b*sec(x), x)
print result_8
if(ques2 == 9):
b = float(input("Enter the coefficent of your cotangent. "))
result_9 = diff(b*cot(x), x)
Differentiation()
sympy
for? Also, consider adding input validation - see e.g. here. \$\endgroup\$