solution_149.py

#!/usr/bin/python3
# ====================================================================
# Calculate time dilation by comparing a moving clock and a
# and a stationary clock
# ====================================================================

import math
import user_interface as ui

light_speed = 186000.0          # speed of light (miles/sec)

print()
print('Time dilation compaired to a stationary observer')

while True:

    print()
    ans = ui.get_user_input('Enter the percentage speed of light: ')

    if not ans: break

    tf,percent = ui.is_float(ans)

    if not tf:
        print()
        print(f'Illegal percentage entered ({ans})')
        continue

    if percent >= 100.0:
        print()
        print(f'Can not go faster than the speed of light ({ans})')
        continue

    speed = light_speed * (percent/100.0)    # moving speed

    time_dilation_factor = 1 / math.sqrt(1.0 - (speed**2/light_speed**2))

    print()
    print(f'time dilation factor = {time_dilation_factor:.4f}')