diff --git a/.DS_Store b/.DS_Store index 912edaf3d516c18ef0069f900487cfdf3c25d8cd..b2022470454d126e6c9a5199ca41c012e51fd8bf 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/cs150/lect05/hello.py b/cs150/lect05/hello.py new file mode 100644 index 0000000000000000000000000000000000000000..4c2efa9a658db7d44ba9b7d1ed9f041cecbded8b --- /dev/null +++ b/cs150/lect05/hello.py @@ -0,0 +1,10 @@ +print("Hello CS 150") + +values = [10, 20, 30] +text = "Hello CS 150" + +# for letter in text: +# print(letter) + +print(len(text)) + diff --git a/cs171/.DS_Store b/cs171/.DS_Store index b3898b5425616f75f1171aa795d0f49dcd349002..6bf5b373bb72831103c16d7cab58e5b0049d5ac2 100644 Binary files a/cs171/.DS_Store and b/cs171/.DS_Store differ diff --git a/cs171/Lect05/hello.py b/cs171/Lect05/hello.py index 061448a8d1383c3b10b99d3b4667be38bd953c3a..6b7757245272673755455f89e197ac52c27a31b1 100644 --- a/cs171/Lect05/hello.py +++ b/cs171/Lect05/hello.py @@ -1 +1,26 @@ -print("Hello CS 171") +def validateInput(prompt, lowBound, highBound): + validData = False + while not validData: + number = input(prompt) + if number.isdigit(): + number = int(number) + if number >= lowBound and number <= highBound: + validData = True + else: + print("Input invalid. Please try again") + else: + print("Input invalid. Please try again") + return number + +grades = [] +numGrades = validateInput("Enter number of grades: ", 1, 999) + +for count in range(1, numGrades+1): + grade = validateInput(f"Enter grade {count}: ", 0, 100) + grades.append(grade) + +low = min(grades) +high = max(grades) +average = sum(grades) / numGrades + +print(grades) diff --git a/cs171/lect07/coolatz.py b/cs171/lect07/coolatz.py new file mode 100644 index 0000000000000000000000000000000000000000..af621e59e2c7e8c6954fa47b06d52b488fcc710d --- /dev/null +++ b/cs171/lect07/coolatz.py @@ -0,0 +1,30 @@ +def coolatz(n): + print(n, end=' ') + if n == 1: + print("Done!") + elif n % 2 == 0: + coolatz(n // 2) + else: + coolatz(3 * n + 1) + + +# Coolatz Conjecture Pseudocode + + + +# Given an arbitrary positive integer: +# Print the number. +# If the number is 1, stop. +# If the number is even, divide it by two and repeat +# If the number is odd, triple it, add one, and repeat + + + + +coolatz(7) + + + + + + diff --git a/cs171/lect07/sumOfDigits.py b/cs171/lect07/sumOfDigits.py new file mode 100644 index 0000000000000000000000000000000000000000..06dd185e4cd15c94c65c624cc9372b69e0e7faaf --- /dev/null +++ b/cs171/lect07/sumOfDigits.py @@ -0,0 +1,17 @@ + + +def sumOfDigits(n): + + # Base Case + if n < 10 and n >= 0: + return n + + # Recursive Case(s) + elif n < 0: + return sumOfDigits(n * -1) + else: + rightMost = n % 10 + rest = n // 10 + return rightMost + sumOfDigits(rest) + +print(sumOfDigits(11)) \ No newline at end of file