mercredi 17 avril 2019

My indents for my loops look strange, is this normal? (python 2)

I'm trying to create loops when certain conditions are met and so far it works but when I try to create more conditions I have to indent them even more in order to get my program to work.

def terrain(surface):
    surface = raw_input("What surface will you be driving on? ")
    while surface != "ice" and surface != "concrete" and surface != "soil" and surface != "asphalt" :
        surface = raw_input("Surface not valid. Please enter a valid surface: ")
    if surface == "ice":
                u = raw_input("what is the velocity of the car in meters per second? ")
                u = int(u)
                while int(u) < 0:
                    u = raw_input("Velocity must be a positive integer: ")
                                while int(u) == 0:
                                    u = raw_input("Velocty must be a number greater than zero: ")
                        while int(u) > 72:
                                                                u = raw_input("This vehicle cannot reach this speed: ")
                a = raw_input("How quickly is the vehicle decelerating? ")
                a = int(a)
                while int(a) > 0:
                    a = raw_input("Deceleration cannot be a positive integer: ")
                else: 
                        s1 = u**2
                        s2 = 2*.08*9.8
                    s = s1/s2
                    print "This is how far the vehicle will travel on ice: "
                    print ("The vehicle will travel %i meters before coming to a complete stop" % (s))
terrain("ice")

I just want to be able to create more loops without the wild indents

Aucun commentaire:

Enregistrer un commentaire