Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
UPS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IPDP
UPS
Commits
ff0dd4d9
Commit
ff0dd4d9
authored
3 years ago
by
vand
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
b4e3e62e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
module5_BMI_calculator.py
+77
-0
77 additions, 0 deletions
module5_BMI_calculator.py
with
77 additions
and
0 deletions
module5_BMI_calculator.py
0 → 100644
+
77
−
0
View file @
ff0dd4d9
import
numpy
as
np
import
matplotlib.pyplot
as
plt
def
input_main_menu
():
print
(
''
)
print
(
'
What would you like to do?
'
)
print
(
'
Type 1, 2, or 3 followed by enter:
'
)
print
(
'
1. Compute and display BMI from weight and height.
'
)
print
(
'
2. Compute and display a normal BMI range from height.
'
)
print
(
'
3. Quit
'
)
i
=
0
while
i
==
0
:
s
=
input
(
'
Choice:
'
)
try
:
i
=
int
(
s
)
except
:
pass
if
not
i
in
[
1
,
2
,
3
]:
print
(
'
You typed
'
+
s
)
print
(
'
You should type 1, 2 or 3 followed by enter.
'
)
i
=
0
return
(
i
)
def
input_measure
(
measure_type
,
units
,
m_min
,
m_max
):
print
(
''
)
m
=
0
while
m
==
0
:
s
=
input
(
'
Type
'
+
measure_type
+
'
followed by enter:
'
)
try
:
m
=
float
(
s
)
except
:
pass
if
m
<
m_min
or
m
>
m_max
:
print
(
'
You typed
'
+
s
)
print
(
'
Type a valid
'
+
measure_type
+
'
in
'
+
units
+
'
.
'
)
m
=
0
return
(
m
)
def
make_plot
(
height
,
weight
=
None
):
h
=
np
.
linspace
(
1.3
,
2.2
)
plt
.
plot
(
h
,
30
*
h
**
2
,
'
r
'
)
plt
.
plot
(
h
,
25
*
h
**
2
,
'
m
'
)
plt
.
plot
(
h
,
18.5
*
h
**
2
,
'
g
'
)
if
weight
is
None
:
wmin
=
18.5
*
height
**
2
wmax
=
25
*
height
**
2
plt
.
plot
([
height
,
height
],
[
wmin
,
wmax
],
'
k
'
)
d
=
f
'
Normal range [
{
wmin
:
.
2
f
}
{
wmax
:
.
2
f
}
]
'
else
:
plt
.
plot
(
height
,
weight
,
'
ko
'
)
d
=
f
'
BMI
{
weight
/
(
height
**
2
)
:
.
2
f
}
'
plt
.
legend
([
'
Obese to overweight
'
,
'
Overweight to normal
'
,
'
Normal to underweight
'
,
d
])
plt
.
xlabel
(
'
Height
'
)
plt
.
ylabel
(
'
Weight
'
)
plt
.
title
(
'
BMI plot
'
)
plt
.
show
()
# main program
print
(
'
*************************
'
)
print
(
'
Welcome to BMI calculator
'
)
choice
=
0
while
choice
<
3
:
choice
=
input_main_menu
()
if
choice
==
1
:
h
=
input_measure
(
'
height
'
,
'
meters
'
,
1
,
2.5
)
w
=
input_measure
(
'
weight
'
,
'
kilograms
'
,
40
,
300
)
make_plot
(
h
,
w
)
elif
choice
==
2
:
h
=
input_measure
(
'
height
'
,
'
meters
'
,
1
,
2.5
)
make_plot
(
h
)
print
(
'
Bye!
'
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment