From fed6e946952c23ad3863f523969031199783bdab Mon Sep 17 00:00:00 2001
From: Daniel Moix <dwm69@drexel.edu>
Date: Tue, 15 Oct 2024 10:52:03 -0400
Subject: [PATCH] Week 4 lecture

---
 cs171/lect04/hello.py     |  7 +++++
 cs171/lect04/immutable.py | 13 +++++++++
 cs171/lect04/lect04.py    | 59 +++++++++++++++++++++++++++++++++++++++
 cs171/lect04/password.py  | 33 ++++++++++++++++++++++
 4 files changed, 112 insertions(+)
 create mode 100644 cs171/lect04/immutable.py
 create mode 100644 cs171/lect04/lect04.py
 create mode 100644 cs171/lect04/password.py

diff --git a/cs171/lect04/hello.py b/cs171/lect04/hello.py
index 061448a..a4119ba 100644
--- a/cs171/lect04/hello.py
+++ b/cs171/lect04/hello.py
@@ -1 +1,8 @@
 print("Hello CS 171")
+
+age = int(input("Enter your age"))
+while age > 21:
+    print("Hello?")
+    age = int(input("Enter your age"))
+
+print("Goodbye")
diff --git a/cs171/lect04/immutable.py b/cs171/lect04/immutable.py
new file mode 100644
index 0000000..da4e42d
--- /dev/null
+++ b/cs171/lect04/immutable.py
@@ -0,0 +1,13 @@
+
+# 
+# name = "Professor"
+# 
+# name = "&"
+# 
+# print(name[0])
+
+num = 17
+dec = 3.14159265
+
+print(f"Your decimal number is {num:x}")
+
diff --git a/cs171/lect04/lect04.py b/cs171/lect04/lect04.py
new file mode 100644
index 0000000..c7db68c
--- /dev/null
+++ b/cs171/lect04/lect04.py
@@ -0,0 +1,59 @@
+# 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
diff --git a/cs171/lect04/password.py b/cs171/lect04/password.py
new file mode 100644
index 0000000..bafb016
--- /dev/null
+++ b/cs171/lect04/password.py
@@ -0,0 +1,33 @@
+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
-- 
GitLab