Remove .md and image files and move python files into main chapter folders
This commit is contained in:
parent
5978779a9a
commit
67806dab6a
159 changed files with 0 additions and 4562 deletions
29
thinkcspy/Chapter-9-Exercises/Problem10.py
Normal file
29
thinkcspy/Chapter-9-Exercises/Problem10.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# Runestone.Academy thinkcspy course
|
||||
# Chapter 9
|
||||
# Problem 10
|
||||
|
||||
def count(substr,theStr):
|
||||
# your code here
|
||||
count = 0
|
||||
charCount = 0
|
||||
pos1 = 0
|
||||
pos2 = len(substr)
|
||||
charPos = len(substr)
|
||||
|
||||
while charCount < len(theStr):
|
||||
if charPos == 1 and substr == theStr[pos1] and (pos2 == len(theStr) or substr != theStr[pos2]):
|
||||
count += 1
|
||||
charCount += 1
|
||||
elif substr == theStr[pos1:pos2]:
|
||||
count += 1
|
||||
charCount += charPos + 1
|
||||
else:
|
||||
charCount += 1
|
||||
|
||||
|
||||
pos1 += 1
|
||||
pos2 += 1
|
||||
|
||||
return count
|
||||
|
||||
print(count("e", "treeleee"))
|
||||
Loading…
Reference in a new issue