Skip to content

Commit aeeabff

Browse files
committed
Add problem set 1 solutions
1 parent 7921ff5 commit aeeabff

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

week 1/lectures/guess-and-check.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cube = 27
2+
for guess in range(cube + 1):
3+
if guess**3 == cube:
4+
print("Cube root of ", cube, " is ", guess)

week 1/pset1/problem-1.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
str = input("Enter a string: ")
2+
vowels = ["a", "e", "i", "o", "u"]
3+
vowel_count = 0
4+
5+
for letter in str:
6+
if letter in vowels:
7+
vowel_count += 1
8+
9+
print("Number of vowels: ", vowel_count)

week 1/pset1/problem-2.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
str = input("Enter a string: ")
2+
bob_count = 0
3+
4+
for i in range(len(str) - 2):
5+
if str[i:(i+3)] == 'bob':
6+
bob_count += 1
7+
8+
print("Number of times bob occurs is: ", bob_count)

week 1/pset1/problem-3.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
str = input("Enter a string: ")
2+
substrings = []
3+
current_substring = []
4+
5+
for i in range(len(str) - 2):
6+
if str[i] <= str[i + 1]:
7+
current_substring.append(str[i])
8+
if str[i + 1] > str[i + 2]:
9+
current_substring.append(str[i + 1])
10+
substrings.append(''.join(current_substring))
11+
current_substring = []
12+
13+
min_substring = substrings[0]
14+
for i in substrings:
15+
if (len(i) > len(min_substring)):
16+
min_substring = i
17+
18+
print(min_substring)

0 commit comments

Comments
 (0)