Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Lecture Demos
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Daniel Moix
Lecture Demos
Commits
c2b7ff4a
Commit
c2b7ff4a
authored
8 months ago
by
Daniel Moix
Browse files
Options
Downloads
Patches
Plain Diff
Week 3 Lecture
parent
40c9c131
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.DS_Store
+0
-0
0 additions, 0 deletions
.DS_Store
cs171/.DS_Store
+0
-0
0 additions, 0 deletions
cs171/.DS_Store
cs171/Lect03/ch5.py
+19
-0
19 additions, 0 deletions
cs171/Lect03/ch5.py
cs171/Lect03/hello.py
+63
-1
63 additions, 1 deletion
cs171/Lect03/hello.py
with
82 additions
and
1 deletion
.DS_Store
0 → 100644
+
0
−
0
View file @
c2b7ff4a
File added
This diff is collapsed.
Click to expand it.
cs171/.DS_Store
0 → 100644
+
0
−
0
View file @
c2b7ff4a
File added
This diff is collapsed.
Click to expand it.
cs171/Lect03/ch5.py
0 → 100644
+
19
−
0
View file @
c2b7ff4a
def
func1
(
i
):
return
i
+
2
def
func2
(
i
):
x
=
func1
(
i
-
1
)
return
x
+
5
def
func3
(
i
):
if
i
<=
0
:
return
0
else
:
print
(
i
)
func3
(
i
//
2
)
i
=
14
a
=
func2
(
i
)
func3
(
i
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
cs171/Lect03/hello.py
+
63
−
1
View file @
c2b7ff4a
print
(
"
Hello CS 171
"
)
# age = int(input("Enter your age: "))
# if age >= 21 :
# print("Line 3 executed.")
# print("Line 4 also is conditional")
# print("This is because of indentation")
def
weightToKg
(
pounds
):
POUNDS_PER_KG
=
0.453592
return
pounds
*
POUNDS_PER_KG
def
heightToMeters
(
feet
,
inches
):
INCHES_PER_FOOT
=
12
INCHES_PER_METER
=
0.0254
totalInches
=
inches
+
feet
*
INCHES_PER_FOOT
return
totalInches
*
INCHES_PER_METER
def
calculateBMI
(
pounds
,
feet
,
inches
):
kg
=
weightToKg
(
pounds
)
meters
=
heightToMeters
(
feet
,
inches
)
bmi
=
kg
/
(
meters
**
2
)
return
bmi
def
weightStatus
(
bmi
):
if
bmi
<
18.5
:
return
"
Underweight
"
elif
bmi
<=
24.9
:
return
"
Normal Weight
"
elif
bmi
<=
29.9
:
return
"
Over Weight
"
else
:
return
"
Obese
"
print
(
"
Welcome to BMI Calculator
"
)
validData
=
True
weight
=
float
(
input
(
"
Enter your weight in pounds:
"
))
if
weight
>
0
:
heightFeet
=
int
(
input
(
"
Enter your height (feet):
"
))
heightInches
=
int
(
input
(
"
Enter your height (inches):
"
))
if
heightFeet
<
0
or
heightInches
<
0
:
print
(
"
Height entry invalid
"
)
validData
=
False
else
:
validData
=
False
print
(
"
Weight is too low.
"
)
print
(
"
Calculation cannot be performed.
"
)
if
validData
==
True
:
print
(
"
Entries were OK. We are clear to calculate.
"
)
kg
=
weightToKg
(
weight
)
print
(
"
Your weight in kg is
"
,
kg
)
meters
=
heightToMeters
(
heightFeet
,
heightInches
)
print
(
"
Your height in meters is
"
,
meters
)
bmi
=
calculateBMI
(
weight
,
heightFeet
,
heightInches
)
print
(
"
Your BMI is
"
,
bmi
)
status
=
weightStatus
(
bmi
)
print
(
"
In this case, the chart says you are
"
,
status
)
else
:
print
(
"
Entry errors. We cannot proceed
"
)
\ 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