Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions number_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,44 @@
# use regex to match numbers and fractions
import re


capture_numbers = r'([^a-zA-Z{./\\}]\d+ |\d+\.\d+| \d+[^/:\\)-}])'

capture_fractions = r'(-?\\frac{\d+}{\d+}[^A-Za-z]|-?\d+\\tinyfrac{\d+}{\d+}[^A-Za-z])'

captured_numbers = []
captured_fractions = []



def count_numbers(text):
"""
counts whole number and decimals i.e -ve and +ve whole numbers decimals
TODO update doc strings
"""
pass #TODO update the fucntion to pass test

with open(text, 'r') as file:
article = file.read()
capture_pattern = re.compile(capture_numbers)
match = capture_pattern.finditer(article)

for num in match:
captured_numbers.append(num.group(0))
return len(captured_numbers)


def count_fraction(text):

with open(text, 'r') as file:
article = file.read()
capture_pattern = re.compile(capture_fractions)
match = capture_pattern.finditer(article)

for frac in match:
captured_fractions.append(frac.group(0))
return len(captured_fractions)


def count_fraction():
"""
counts fractional numbers i.e both negative an positive
TODO update doc strings
"""
pass #TODO update the fucntion to pass test


## Use this for your debugging purposes (all print statements should go here)
if __name__ == "__main__":
Expand Down