DEV Community

Roasty
Roasty

Posted on

Codecademy|software-development-concepts-project

Started the course, got overwhelmed while reading the project, but finished it eventually when stated to write.
Did not make a flowchart coz I don't like it.

Pseudo-code:
define text
define pattern
if the entire text hasn't been searched:
iterate to the next character of the text
create match_count and set it to 0
if the entire pattern hasn't been searched:
if this character from the pattern is equal to the character from text:
increment match_count
if match_count == length of pattern:

pattern found!

Code:

text = input('text: ')
pattern = input('pattern: ')

text_low = text.lower()
pattern_low = pattern.lower()

for index in range(len(text_low) - len(pattern_low) + 1):
match_count = 0

for char in range(len(pattern_low)):
    if pattern_low[char] == text_low[index + char]:
        match_count += 1

if match_count == len(pattern_low):
    print(f'The pattern value of "{pattern}" can be found in text value of "{text}".')
    break
Enter fullscreen mode Exit fullscreen mode

else:
print(f'The pattern value of "{pattern}" can not be found in text value of "{text}".')

Top comments (0)