# Problem 3: Rocket Recursion from math import exp # STAGE 1: surface to LEO = 9.4 km/s # STAGE 2: LEO to moon capture = 3.26 km/s # STAGE 3: moon capture to surface = 2.41 km/s # Initialize the stages data # A list containing multiple dictionaries stages = [{'d_v': 9.4, 'v_e': 2.3, 'sdm': 16000}, {'d_v': 3.26, 'v_e': 2.3, 'sdm': 8000}, {'d_v': 2.41, 'v_e': 2.3, 'sdm': 4500}] # WHERE # d_v = delta velocity # v_e = exhaust velocity # sdm = dry mass of that specific stage def wet_mass(stages): """Recursive solution for finding the wet mass of a series of stages Input: list of dictionaries with defined values: Example: stages = [{'d_v': 9.4, 'v_e': 2.3, 'sdm': 16000}, {'d_v': 3.26, 'v_e': 2.3, 'sdm': 8000}, {'d_v': 2.41, 'v_e': 2.3, 'sdm': 4500}] """ # if there are no more stages, return 0 if len(stages) == 0: return 0 # otherwise, return the wet mass, and calculate # the next stage else: # index the first dictionary in the list workingdict = stages[0] d_v = workingdict.get('d_v') v_e = workingdict.get('v_e') sdm = workingdict.get('sdm') # m_o = m_f * exp(d_v/v_e) return (wet_mass(stages[1:])+sdm)*exp(d_v/v_e) # our above return statement indexes and passes the # rest of our dictionaries in the list # for the next recursion. # Find the initial wet launch mass needed and print it. launch_mass = wet_mass(stages) print(f"Launch Mass: {launch_mass:.2f} kg")