solution_096b.py

#!/usr/bin/python3
# Trains Doppler shift

c = 1086.9                    # speed of sound ft/sec

v = (40.0 * 5280.0)/(60 * 60) # train's velocity ft/sec

fs = 440                      # Train's whistles (440 Hz)

def doppler_shift(v):
   fr = fs * (1 / (1 + (v/c)))
   print(f"Train's  frequency : {fs:>.2f} Hz")
   print(f"Train's  velocity  : {v:>.2f} ft/sec")
   print(f"receiving frequency: {fr:>.2f} Hz")
   print(f"Doppler shift      : {(fr-fs):>.2f} Hz")

print()
print('moving away from the observer')
doppler_shift(v)
print()
print('moving away towards the observe')
doppler_shift(-v)