I tried to create a basic Slingshot algorithm... Basicly i tried to eliminate every problems in my code but now it doesn't do anything

Viewed 30
from math import sin, cos


def Sling():
    b_h =   float(input("Input starting speed:   "))
    b_angl = float(input("Input starting angle:   "))
    vy = b_h * sin(b_angl)
    vx = b_h * cos(b_angl)
    g = 9.8
    t = (vy/8)
    Max_height = (vy - (-g*t*t)) # max height of the throw
    tx = 0

    Projectile_CS = (vy * tx) - (-g*tx*tx) # current spot of the projectile
    
    while Projectile_CS >= 0:
        tx += 0.1
    else:
        print("Done")
        Max_distance = tx * vx

        print("Max")
    
        for x in range(round(float(Max_height)/5)):
            print("*")
    
        print("0", "_" * t, "_" * round((Max_distance)/5))
    
        print("The maximum height is:   ", round(Max_height))
        print("Max distance is:  ", round(Max_distance))
     
        return 

Sling() 

After the while Projectile_CS >= 0: part of the code, it doesn't do anything, or looks like it. I can stop the code or restart with debugging but it doesn't help.

1 Answers

You never update Projectile_cs in the while loop, therefore you get stuck inside it

Your while loop continues until Projectile_speed value is < 0, but since you never change projectile_speed value in the while loop it will forever be < 0

For your code to work you have to update your variable in the while loop, according to what you did earlier it would probably look something like that

Projectile_CS = (vy * tx) - (-g*tx*tx)


while Projectile_CS >= 0:
    tx += 0.1
    Projectile_CS = (vy * tx) - (-g*tx*tx)
Related