Python - Calculating Velocity of a Star/Galaxy Using the Doppler Shift

by matt392 in Circuits > Software

54 Views, 1 Favorites, 0 Comments

Python - Calculating Velocity of a Star/Galaxy Using the Doppler Shift

TelescopeDoppler.jpg
Python program is below and attached.
-----------
print ("Calculate the velocity of a galaxy using the Doppler Shift.")
answer = "y"

# Start while loop
while (answer == "y"):
    # Observed wavelength entered by user and converted to an integer
    observedWavelength = int(input("Enter the observed wavelength in Angstroms: "))
    
    # Wavelength of element entered by user and converted to an integer
    elementWavelength = int(input("Enter the element's wavelength in Angstroms: "))

    # Calculate the change or shift in the wavelength
    changeWavelength = observedWavelength - elementWavelength
    print ("The speed of light is: 3 x 10^5 km/s.")
    print ("The formula is: velocity = speed of light * (change in wavelength/wavelength of the element)")

    # Calculate the velocity below
    velocity =  (3*(10**5)) * (changeWavelength/elementWavelength) 
    print ("The velocity of the galaxy is:", velocity, "km/s")
    print ("Note that a positive value means the object is moving away from Earth.")
    print ("A negative value means that the object is moving towards Earth.")
    answer = input("Would you like to do another calculation? (y/n) ")
# End while loop

print ("Thank you to Professor Morgan at the University of Northern Iowa for the formula and explanation.")

Downloads