Preparing git repo for final project

This commit is contained in:
2023-07-09 11:19:26 +02:00
parent 6a38966eef
commit 63d06d6b35
67 changed files with 1587 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
from um import count
def main():
test_count_ums()
test_words_containing_ums()
test_punctuation()
test_from_cs50p()
def test_count_ums():
assert count("Hello, um, world") == 1
assert count("Hello um, um, world um") == 3
assert count("Um Hello, um, world um") == 3
def test_words_containing_ums():
assert count("instrumentation") == 0
assert count("umbrella") == 0
assert count("momentum") == 0
def test_punctuation():
assert count("Hello um?") == 1
assert count("Hello um!") == 1
assert count("Hello um") == 1
assert count("Hello um.") == 1
def test_from_cs50p():
assert count("um") == 1
assert count("um?") == 1
assert count("Um, thanks for the album.") == 1
assert count("Um, thanks, um...") == 2
if __name__ == '__main__':
main()

15
problems/pset7/um/um.py Normal file
View File

@@ -0,0 +1,15 @@
import re
um_regex = re.compile(r"\bum\b", re.IGNORECASE)
def main():
print(count(input("Text: ")))
def count(s):
return len(um_regex.findall(s))
if __name__ == "__main__":
main()