Python - Hubble's Law Calulation to Find the Velocity of a Galaxy

by matt392 in Circuits > Software

58 Views, 1 Favorites, 0 Comments

Python - Hubble's Law Calulation to Find the Velocity of a Galaxy

hubbleformula.png
hubblesconstant.png
print ("Calculate the velocity of a galaxy using Hubble's Law.")
answer = "y"

while (answer == "y"):
    # Distance entered by user and converted to an integer
    distance = int(input("Enter the distance in mega-parsecs: "))
    print ("The Hubble Constant is: 70 km/s/Mpc.")
    print ("The formula is: velocity = Hubble Constant * distance")
    # Calculate the velocity below
    velocity = distance * 70
    print ("The velocity of the galaxy is:", velocity, "mega-parsecs (Mpc)")
    answer = input("Would you like to do another calculation? (y/n) ")

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

Downloads