Exercise 1
Define a Satellite()
class that allows you to instantiate objects simulating
artificial satellites launched into space, around the earth.
The constructor of this class will initialize the following instance attributes, with the default values indicated : mass = 100, speed = 0
When we instantiate a new Satellite() object, we can choose its name, its mass and its speed.
The following methods will be defined:
pulse(strength, duration)
will change the satellite speed. To calculate this new speed: force (in newton) * last (in seconds) / mass + old speed
display_speed()
will display the name of the satellite and its current speed.
energy()
will return the satellite kinetic energy value to the calling program.
the kinetic energy is calculated using the formula 0.5*m*v**2
Examples of use of this class :
s1 = Satellite('Zoe', mass =250, speed =10)
s1.pulse(500, 15)
s1.display_speed()
=> Zoe satellite speed = 40 m/s
print (s1.energie())
=> 200000
s1.pulse(500, 15)
s1.display_speed()
=> Zoe satellite speed = 70 m/s.
print (s1.energie()=
=>
612500
Exercise 2
Define
a Circle()
class.
The objects built from this class will be circles of various sizes.
In addition to the constructor method (which will use a radius
parameter), you will define a
surface()
method,
which must return the circle surface.
Then define a Cylinder() class derived from the previous one. The constructor of this new class will include the two parameters radius and height. You will add a volume() method that will return the volume of the cylinder.
(Reminder : Volume of a cylinder = section area x height).
Example of use of this class :
cyl = Cylinder(5, 7)
print (cyl.surface())
=> 78.54
print (cyl.volume())
=>
549.78