|
Note: Parts of this project are based on exercises in the text. To the extent that instructions here differ from those in the text, the instructions on these web pages take precedence. |
circumference(r)
- to return the circumference of a circle with radius
r
. [2πr
]area(r)
- to return the area of a circle with radius r
.
[πr2
]surface(r)
- to return the surface area of a sphere with radius
r
. [4πr2
]volume(r)
- to return the volume of a sphere with radius
r
. [4πr3/3
]math.pi
(after importing the math module) for the value of π in all of
these calculations.-bash-4.2$ python3 sphere.py enter radius: 2.5 circumference: 15.7 circle area: 19.6 sphere volume: 65.4 sphere surface area: 78.5 -bash-4.2$ python3 sphere.py enter radius: 10 circumference: 62.8 circle area: 314.2 sphere volume: 4188.8 sphere surface area: 1256.6
height(D, W, H)
- where D, W and H are described above.width(W, H, screenHeight)
- where W and H as above, and screenHeight is the result of
the height function.-bash-4.2$ python3 screensize.py enter D, W, H (separated by commas): 51, 4, 3 width = 40.8, height = 30.6 -bash-4.2$ python3 screensize.py enter D, W, H (separated by commas): 64, 16, 9 width = 55.8, height = 31.4
mypi(n)
- where n
is the number of terms to include.(1)
.
If n is equal to 4, include the first four terms exactly as they are shown in
the exercise description on page 81. And so on as n increases.-bash-4.2$ python3 mypi.py enter number of terms: 10 estimate of pi is 3.1415905109 -bash-4.2$ python3 mypi.py enter number of terms: 1 estimate of pi is 3.4641016151 -bash-4.2$ python3 mypi.py enter number of terms: 25 estimate of pi is 3.1415926536
bmi(inches, pounds)
- returns the index using the formula below.category(index)
- returns the string category of the index.At left is the formula for calculating BMI, given a person's weight in kilograms and height in meters. |
['Underweight','Normal','Overweight','Obese']
in accordance with
the following table:
Category string | BMI range |
---|---|
Underweight | < 18.5 |
Normal | 18.5 to just less than 25 |
Overweight | 25 to just less than 30 |
Obese | 30 or greater |
-bash-4.2$ python3 bmi.py enter height in inches: 69 enter weight in pounds: 175 BMI is 25.8: Overweight -bash-4.2$ python3 bmi.py enter height in inches: 64.2 enter weight in pounds: 118.5 BMI is 20.2: NormalBe sure your results are accurate for other heights and weights too.
cd
to the
same directory as your source code files, then type the following (careful -
turning in to uppercase P-one, P1, at class account cs8c):
turnin P1@cs8c sphere.py screensize.py mypi.py bmi.pyIf you are working with a partner, be sure that both partners names are in the comments at the top of all source files.