Skip to content
Snippets Groups Projects
Commit fed6e946 authored by Daniel Moix's avatar Daniel Moix
Browse files

Week 4 lecture

parent c2b7ff4a
Branches
No related tags found
No related merge requests found
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")
#
# name = "Professor"
#
# name = "&"
#
# print(name[0])
num = 17
dec = 3.14159265
print(f"Your decimal number is {num:x}")
# 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
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment