Answer:
Following are the python code to this question:
class Drone: #define class
def __init__(self): #define constructor
self.speed = 0.0 #define variable speed and assign value
self.height = 0.0 #define variable speed and assign value
def accelerate(self): #define method accelerate
self.speed += 10 #add value 10 in speed
def decelerate(self): #define method decelerate
if(self.speed >= 10): #define condition that checks speed value is greater then equal to 10
self.speed -= 10 #subtract value of speed by 10
else: #else block
self.speed = 0 #assign value 0 in speed variable
def ascend(self): #define method ascend
self.height += 10 #add value 10 in height
def descend(self): #define method descend
if(self.height>=10): #define condition that checks height value is greater then equal to 10
self.height -= 10 #subtract value of height by 10
else: #else block
self.height = 0 #assign value 0 in variable height
drone = Drone() #create class object
f = True #define variable f and assign bool value
while(f): #define that calculate value
c = int(input("please select by your choice: for accelerate = 1, for decelerate = 2, for ascend = 3,for descend = 4,for exit = 0: "))
#define variable that take input from user and convert value in integer
if(c==1): #check c value is equal to 1
drone.accelerate() #call accelerate method
Output:
Please find the attachment.
Step-by-step explanation:
In the code part there are some code which can't inserted in so, we give the image of the full code, please find in attachment.
In the python code, a class "Drone", is declared, inside the class, a constructor, and four methods "accelerate, decelerate, ascend, and descend" is declared.
- In the "accelerate and descend" method we increment and decrements its variable value by 10, and method "decelerate and ascend" uses conditional statement that checks speed and height variable value is greater then equal to 10, if the value is true it will subtract the value by 10, otherwise set the value 0, and in next line, the class object is created.
- In the last step, a c variable is declared, that input from the user according to choice, and convert the value into the integer. In this, a conditional statement is used, that checks "c" value and call the above method, which can be described in the given example:
- if the value is 1, it will call accelerate method, otherwise it will go to else if section.
- In this else if value is equal to 2, it will call decelerate method,
- if this condition is false, it will check another value, that is value is equal to 3, in this, it will call ascend method.
- if the value is equal to 4, it will call descend method.
- If above condition is false, it will print speed and height value.