-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMV.py
More file actions
50 lines (44 loc) · 1.49 KB
/
Copy pathMV.py
File metadata and controls
50 lines (44 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Write a class called Thing. The constructor for Thing should
# have two required parameters: its mass and its volume, in
# that order. These should be saved as the object's mass and
# volume attributes, respectively.
#
# Additionally, the object should have two other attributes,
# weight and density. weight should be calculated by multiplying
# the mass by the gravity on earth, 9.8, and rounding to the
# nearest tenth. density should be calculated by dividing mass
# by volume and rounding to the nearest tenth.
#
# When the constructor has finished initalizing the object, it
# should thus have four attributes: mass, volume, weight, and
# density. mass and volume will have the same values given to
# the constructor, and weight and density will be calculated
# based on those values.
# Add your class here!
## round to nearest 10th, just add 1..to the round function after the number)
class Thing:
def __init__(self, mass, volume):
self.mass = mass
self.volume = volume
self.weight = round(mass * 9.8, 1)
self.density = round(mass/volume,1)
# The following lines of code will test your object. If it
# is written correctly, they will print:
# 10
# 5
# 98.0
# 2.0
# 14.0
# 75.0
# 137.2
# 0.2
thing_1 = Thing(10.0, 5.0)
thing_2 = Thing(14.0, 75.0)
print(thing_1.mass)
print(thing_1.volume)
print(thing_1.weight)
print(thing_1.density)
print(thing_2.mass)
print(thing_2.volume)
print(thing_2.weight)
print(thing_2.density)