Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading