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
fed6e946
Commit
fed6e946
authored
8 months ago
by
Daniel Moix
Browse files
Options
Downloads
Patches
Plain Diff
Week 4 lecture
parent
c2b7ff4a
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
cs171/lect04/hello.py
+7
-0
7 additions, 0 deletions
cs171/lect04/hello.py
cs171/lect04/immutable.py
+13
-0
13 additions, 0 deletions
cs171/lect04/immutable.py
cs171/lect04/lect04.py
+59
-0
59 additions, 0 deletions
cs171/lect04/lect04.py
cs171/lect04/password.py
+33
-0
33 additions, 0 deletions
cs171/lect04/password.py
with
112 additions
and
0 deletions
cs171/lect04/hello.py
+
7
−
0
View file @
fed6e946
print
(
"
Hello CS 171
"
)
print
(
"
Hello CS 171
"
)
age
=
int
(
input
(
"
Enter your age
"
))
while
age
>
21
:
print
(
"
Hello?
"
)
age
=
int
(
input
(
"
Enter your age
"
))
print
(
"
Goodbye
"
)
This diff is collapsed.
Click to expand it.
cs171/lect04/immutable.py
0 → 100644
+
13
−
0
View file @
fed6e946
#
# name = "Professor"
#
# name = "&"
#
# print(name[0])
num
=
17
dec
=
3.14159265
print
(
f
"
Your decimal number is
{
num
:
x
}
"
)
This diff is collapsed.
Click to expand it.
cs171/lect04/lect04.py
0 → 100644
+
59
−
0
View file @
fed6e946
# 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
"
def
validateInput
(
prompt
,
lowBound
,
highBound
):
validData
=
False
while
not
validData
:
number
=
int
(
input
(
prompt
))
if
number
>=
lowBound
and
number
<=
highBound
:
validData
=
True
else
:
print
(
"
Input invalid. Please try again
"
)
return
number
print
(
"
Welcome to BMI Calculator
"
)
weight
=
validateInput
(
"
Enter your weight in pounds:
"
,
0
,
9999
)
heightFeet
=
validateInput
(
"
Enter your height (feet):
"
,
0
,
10
)
heightInches
=
validateInput
(
"
Enter your height (inches):
"
,
0
,
11
)
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
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
cs171/lect04/password.py
0 → 100644
+
33
−
0
View file @
fed6e946
def
checkPassword
(
entry
):
if
len
(
entry
)
<
8
:
return
False
i
=
0
digits
=
0
lowers
=
0
uppers
=
0
special
=
0
while
i
<
len
(
entry
):
ch
=
entry
[
i
]
if
ch
.
isdigit
():
digits
=
digits
+
1
elif
ch
.
islower
():
lowers
=
lowers
+
1
elif
ch
.
isupper
():
uppers
=
uppers
+
1
else
:
special
+=
1
i
=
i
+
1
if
digits
>=
1
and
lowers
>=
1
and
uppers
>=
1
and
special
>=
1
:
return
True
return
False
entry
=
input
(
"
Enter your password:
"
)
result
=
checkPassword
(
entry
)
if
result
:
print
(
"
Password meets all requirements
"
)
else
:
print
(
"
Password fails
"
)
\ 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