samedi 2 décembre 2017

Why is my python program printing a statement twice at the end?

So im finished with the program as far as i can tell but i have a formattting type issue where the last print statement in the "def main()" function is printing twice and i cant figure out why- very annoying. Anyway im sure it's something simple that im missing, heres my code:

import math

#----------------------------------------------------
# distance(draw,angle)
#
# This function computes the distance of the shot
#----------------------------------------------------

def distance(draw,angle):
    velocity = draw*10
    x = (angle)
    sin_deg = math.sin(math.radians(2*x))
    g = 32.2
    dist = (((velocity**2) * sin_deg) / g)
    return dist

#----------------------------------------------------
# Main Program #
#----------------------------------------------------

dist_to_pig = int(input("Distance to pig (feet) -------- "))

def main():
    angle_of_elev = float(input("Angle of elevation (degrees) -- "))
    draw_length = float(input("Draw length (inches) ---------- "))
    print()
    distance_calc = round(distance(draw_length,angle_of_elev))
    short_result = int(round(dist_to_pig - distance_calc))
    long_result = int(round(distance_calc - dist_to_pig))


    if distance_calc < (dist_to_pig - 2):
        print("Result of shot ---------------- ", (short_result - 2), "feet too short")
        print()
        main()
    if distance_calc > (dist_to_pig + 2):
        print("Result of shot ---------------- ", (long_result - 2), "feet too long")
        print()
        main()
    else:
        print("OINK!")

#----------------------------------------------------
# Execution #
#----------------------------------------------------

main()

If you see any other problems in my code feel free to point that out. thanks!

Aucun commentaire:

Enregistrer un commentaire