Python - Specific Impulse for an Engine by Weight for Earth, Moon, Mars, Europa and Io

by matt392 in Circuits > Software

40 Views, 1 Favorites, 0 Comments

Python - Specific Impulse for an Engine by Weight for Earth, Moon, Mars, Europa and Io

SpecificImpulseWeight.jpg
SpecificImpulse2.png
SpecificImpulseFormula.png
print ("This program will calculate the Specific Impulse by Weight.")

import math

###  Formula for calculating the Specific Impulse by Weight:
#  SpecificImpulse = ( (Thrust * BurningTime)/(PropellantMass * AccelerationDueToGravity) )
#  AccelerationDueToGravity = 9.80665
###########################################

# Enter the Thrust, BurningTime, PropellantMass, AcceleratingDueToGravity

#  Do 5 functions one for Earth, one for Moon, one for Mars, Europa, Io
# EarthAccelerationDueToGravity = 9.80665
# MoonAccelerationDueToGravity = 1.6
# MarsAccelerationDueToGravity = 3.7
# EuropaAccelerationDueToGravity = 1.314
# IoAccelerationDueToGravity = 1.81

def EarthSolveForSpecificImpulseByWeight():
    print ("Solving for the the Specific Impulse by Weight for the Earth.")
    # Enter the Thrust 
    Thrust = float(input("Enter the thrust: ") )
    # Enter the BurningTime in seconds
    BurningTime = float(input("Enter the Burning Time in seconds: ") )
    # Enter the PropellantMass
    PropellantMass = float(input("Enter the Propellant Mass: ") )
    # EarthAccelerationDueToGravity is a constant
    EarthAccelerationDueToGravity = 9.80665
    # Calculate the top of the fraction
    TopOfFraction = (Thrust * BurningTime)
    print("The top of thefraction is: ", TopOfFraction)
    # Calculate the bottom of the fraction
    BottomOfFraction = (PropellantMass * EarthAccelerationDueToGravity)
    print("The bottom of the fraction is: ", BottomOfFraction)
    # Calculate the fraction
    SpecificImpulse = (TopOfFraction/BottomOfFraction)
    print("The Specific Impulse on the Earth is: ", SpecificImpulse)

def MoonSolveForSpecificImpulseByWeight():
    print ("Solving for the the Specific Impulse by Weight for the Moon.")
    # Enter the Thrust 
    Thrust = float(input("Enter the thrust: ") )
    # Enter the BurningTime in seconds
    BurningTime = float(input("Enter the Burning Time in seconds: ") )
    # Enter the PropellantMass
    PropellantMass = float(input("Enter the Propellant Mass: ") )
    # MoonAccelerationDueToGravity is a constant
    MoonAccelerationDueToGravity = 1.6
    # Calculate the top of the fraction
    TopOfFraction = (Thrust * BurningTime)
    print("The top of thefraction is: ", TopOfFraction)
    # Calculate the bottom of the fraction
    BottomOfFraction = (PropellantMass * MoonAccelerationDueToGravity)
    print("The bottom of the fraction is: ", BottomOfFraction)
    # Calculate the fraction
    SpecificImpulse = (TopOfFraction/BottomOfFraction)
    print("The Specific Impulse on the Moon is: ", SpecificImpulse)

def MarsSolveForSpecificImpulseByWeight():
    print ("Solving for the the Specific Impulse by Weight for Mars.")
    # Enter the Thrust 
    Thrust = float(input("Enter the thrust: ") )
    # Enter the BurningTime in seconds
    BurningTime = float(input("Enter the Burning Time in seconds: ") )
    # Enter the PropellantMass
    PropellantMass = float(input("Enter the Propellant Mass: ") )
    # MarsAccelerationDueToGravity is a constant
    MarsAccelerationDueToGravity = 3.7
    # Calculate the top of the fraction
    TopOfFraction = (Thrust * BurningTime)
    print("The top of thefraction is: ", TopOfFraction)
    # Calculate the bottom of the fraction
    BottomOfFraction = (PropellantMass * MarsAccelerationDueToGravity)
    print("The bottom of the fraction is: ", BottomOfFraction)
    # Calculate the fraction
    SpecificImpulse = (TopOfFraction/BottomOfFraction)
    print("The Specific Impulse on the Mars is: ", SpecificImpulse)

def EuropaSolveForSpecificImpulseByWeight():
    print ("Solving for the the Specific Impulse by Weight for Europa.")
    # Enter the Thrust 
    Thrust = float(input("Enter the thrust: ") )
    # Enter the BurningTime in seconds
    BurningTime = float(input("Enter the Burning Time in seconds: ") )
    # Enter the PropellantMass
    PropellantMass = float(input("Enter the Propellant Mass: ") )
    # EuropaAccelerationDueToGravity is a constant
    EuropaAccelerationDueToGravity = 1.314
    # Calculate the top of the fraction
    TopOfFraction = (Thrust * BurningTime)
    print("The top of thefraction is: ", TopOfFraction)
    # Calculate the bottom of the fraction
    BottomOfFraction = (PropellantMass * EuropaAccelerationDueToGravity)
    print("The bottom of the fraction is: ", BottomOfFraction)
    # Calculate the fraction
    SpecificImpulse = (TopOfFraction/BottomOfFraction)
    print("The Specific Impulse on Europa is: ", SpecificImpulse)

def IoSolveForSpecificImpulseByWeight():
    print ("Solving for the the Specific Impulse by Weight for Io.")
    # Enter the Thrust 
    Thrust = float(input("Enter the thrust: ") )
    # Enter the BurningTime in seconds
    BurningTime = float(input("Enter the Burning Time in seconds: ") )
    # Enter the PropellantMass
    PropellantMass = float(input("Enter the Propellant Mass: ") )
    # EuropaAccelerationDueToGravity is a constant
    IoAccelerationDueToGravity = 1.81
    # Calculate the top of the fraction
    TopOfFraction = (Thrust * BurningTime)
    print("The top of thefraction is: ", TopOfFraction)
    # Calculate the bottom of the fraction
    BottomOfFraction = (PropellantMass * IoAccelerationDueToGravity)
    print("The bottom of the fraction is: ", BottomOfFraction)
    # Calculate the fraction
    SpecificImpulse = (TopOfFraction/BottomOfFraction)
    print("The Specific Impulse on Io is: ", SpecificImpulse)

ContinueCalculations = "y"

while (ContinueCalculations=="y"):
    print ("Which celestial body would you like to calculate Specific Impulse by Weight?")
    CelestialBody = str(input("Enter (1) for Earth, (2) for the Moon, (3) for Mars, (4) for Europa, " +
                              "(5) for Io or (n) to quit: "))
    if (CelestialBody == "1"):
        EarthSolveForSpecificImpulseByWeight()
    elif (CelestialBody == "2"):
        MoonSolveForSpecificImpulseByWeight()
    elif (CelestialBody == "3"):
        MarsSolveForSpecificImpulseByWeight()
    elif (CelestialBody == "4"):
        EuropaSolveForSpecificImpulseByWeight()
    elif (CelestialBody == "5"):
        IoSolveForSpecificImpulseByWeight()
    elif (CelestialBody == "n"):
        ContinueCalculations = "n"

print("==================================")
print ("Thank you to www.fxsolver.com for assistance with this formula.")