Programming a distance formula with Python



Fittingly for a creativity and imaginative solutions boffin such as me, I had the idea of programming with Python (version 3.10.2 in this case) this very simple program with which we obtain the distance 'D' to the horizon 'h'. All Python releases are Open Source, and programmers have voted by using Python enough that it's now the firs-ranked language in the world (see https://www.tiobe.com/tiobe-index/ for details). Only for both scientific and landscape minds, it's not difficult to suspect that the horizon is farther away as we go up, and that the sphericity of the Earth must have an influence. Therefore, by entering the value of the height at which we are, we will know how far away the horizon line is. The mathematical formula that defines it takes into account the radius of the Earth. The program can be called GAG_Dh.py, and run with Python IDLE (Python GUI), maybe already installed on your computer.

#This is my simple GAG_Dh program
print("___________________________\n")
print("Distance to the horizon line")
print("___________________________\n")
for i in [1,2,3,4,5,6,7,8,9,10]:
print("Write the height:", end = " ")
ob_height = float(input())
earth_r = 6371000
dist = (2 *ob_height * earth_r + ob_height **2)**0.5 #Formula
dist_km = int(dist * 0.001)
print("The horizon is at a distance of", dist_km, 'kms\n')
print("======= TRY AGAIN ========\n")