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

Lecture 04

parent d7ae4533
Branches
No related tags found
No related merge requests found
No preview for this file type
print("Hello CS 150")
values = [10, 20, 30]
text = "Hello CS 150"
# for letter in text:
# print(letter)
print(len(text))
No preview for this file type
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)
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)
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment