#! /usr/bin/env python """ relativity.py is program which calculates the time in years that a spaceship takes to reach its destination as observed by someone on earth and as observed on the spaceship The program asks the user to input the restframe distance and the spaceship speed. Paul Eugenio PHZ4151C Jan 15, 2019 ### PROGRAM OUTPUT ### hpc-login-24 511% relativity.py Enter distance in light years: 10 Enter velocity as fraction of c: .99 Time on Earth is 10.10 years Time on the spaceship is 1.42 years. """ # program header code from __future__ import division, print_function from math import sqrt # main body of program distance = float(raw_input("Enter distance in light years: ")) # v cannot be greater than or equal to c velocity = 2 while velocity >= 1: velocity = float(raw_input("Enter velocity as fraction of c: ")) if velocity >= 1: print("Velocity cannot be equal to or greater than the spped of light!") gamma = 1/sqrt(1 - velocity**2) # time on Earth = proper distance / velocity print( "Time on Earth is {0:.2f} years".format(distance/velocity) ) # time on spaceship = contracted distance (x' = x/gamma) / velocity print( "Time on the spaceship is {0:.2f} years.".format( (distance/gamma)/velocity) )