def main(): # create Drone object drone = Drone() # set choice to 5 choice = 5 while(choice != 0): # input choice choice = int(input( "Enter 1 for accelerate, 2 for decelerate, 3 for ascend, 4 for descend, 0 for exit: ")) # if choice is 1, call accelerate method of drone object if(choice == 1): drone.accelerate() # if choice is 2, call decelerate method of drone object if(choice == 2): drone.decelerate() # if choice is 3, call ascend method of drone object if(choice == 3): drone.ascend() # if choice is 4, call descend method of drone object if(choice == 4): drone.descend() if(choice == 0): exit() # display speed and height of drone object print(drone.__str__())
from drone import Drone if __name__ == '__main__': possible_options = {0, 1, 2, 3, 4} rq21 = Drone() while True: try: innie = int( input( "Enter 1 for accelerate, 2 for decelerate, 3 for ascend, 4 for descend, 0 for exit: " )) if innie == 0: print(rq21.__str__()) break elif innie == 1: rq21.accelerate() elif innie == 2: rq21.decelerate() elif innie == 3: rq21.ascend() elif innie == 4: rq21.descend() else: raise ValueError print(rq21.__str__()) except ValueError: print("Please enter one of the follow integers:", possible_options) continue
my_drone = Drone() x = 0 while x < 25: i = random.randint(1, 4) if i == 1: my_drone.accelerate() elif i == 2: my_drone.decelerate() elif i == 3: my_drone.ascend() elif i == 4: my_drone.descend() my_drone.__str__() x += 1 time.sleep(0.5) print("Drone is beginning landing procedure...") time.sleep(3) speed = my_drone.getSpeed() height = my_drone.getHeight() while speed != 0 or height != 0: if speed < 0: my_drone.accelerate() elif speed > 0: my_drone.decelerate() elif height > 0: