Create a Python project fly_drone.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Create a Python project fly_drone.  Add a Python file drone.py to this project.  Define a class Drone in this file.  This class has the following five methods:

 

  • __init__ : Create two instance variables to store the speed and the height of the drone. Initialize them to 0.0. This method has no parameters other than self and no return value.
  • accelerate : Increase the speed of the drone by 10. This method has no parameters other than selfand no return value.
  • decelerate : Decrease the speed of the drone by 10. The new speed cannot be negative.  This method has no parameters other than self and no return value.
  • ascend : Increase the height of the drone by 10. This method has no parameters other than self and no return value.
  • descend : Decrease the height of the drone by 10. The new height cannot be negative. This method has no parameters other than self and no return value.

 

   The following class diagram shows the design of this class:

 

Drone

+speed: Float

+height: Float

+Drone()

+accelerate()

+decelerate()

+ascend()

+descend()

 

Add a file fly_drone_main.py to this project.  In this main module, create an instance of Drone.  Write a loop to control the speed and height of the drone.  In the loop, ask the user to enter 1 for acceleration, 2 for deceleration, 3 for ascending, 4 for descending, or 0 for exit.  Call the appropriate method of the Droneobject to change the speed or height of the drone.  Every time the speed or height of the drone changes, display the speed and height.

 

The following shows a sample test run:

 

Enter 1 for accelerate, 2 for decelerate, 3 for ascend, 4 for descend, 0 for exit: 1

Speed: 10  Height: 0

 

Enter 1 for accelerate, 2 for decelerate, 3 for ascend, 4 for descend, 0 for exit: 1

Speed: 20  Height: 0

 

Enter 1 for accelerate, 2 for decelerate, 3 for ascend, 4 for descend, 0 for exit: 3

Speed: 20  Height: 10

 

Enter 1 for accelerate, 2 for decelerate, 3 for ascend, 4 for descend, 0 for exit: 3

Speed: 20  Height: 20

 

Enter 1 for accelerate, 2 for decelerate, 3 for ascend, 4 for descend, 0 for exit: 3

Speed: 20  Height: 30

 

Enter 1 for accelerate, 2 for decelerate, 3 for ascend, 4 for descend, 0 for exit: 2

Speed: 10  Height: 30

 

Enter 1 for accelerate, 2 for decelerate, 3 for ascend, 4 for descend, 0 for exit: 0

Speed: 10  Height: 30

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education