Question: USING PYTHON PROGRAMMING AND WHILE LOOPS. DO NOT USE BREAK,PASS,,CONTINUE AND FOR LOOPS For this part of the homework, you will write code to search
USING PYTHON PROGRAMMING AND WHILE LOOPS. DO NOT USE BREAK,PASS,,CONTINUE AND FOR LOOPS
For this part of the homework, you will write code to search through
a phrase
,
looking for
occurrences of a
word
. Each time an occurrence is found, the
program
must
report the index at which
the word
star
ts as well.
After
searching, it must print out the total number of times word was found.
The program must be case
in
sensitive, and must use a function called
inPhrase()
that takes in the phrase and word as its two formal
parameters.
All of the searching
and printing of results must happen inside
the
inPhrase()
function.
Inside
main()
, the program must ensure that the word is shorter than the
phrase, re
-
prompting the user as necessary. You may assume that both
inputs will be at least 1 character.
SAMPLE OUTPUT:
bash
-
4.1$ python hw5_part2.py
Please enter a phrase:
Dogs are good, dogs dogs dogs
Please enter a word to search for:
DOGS
Found DOG
S at index 0
Found DOGS at index 15
Found DOGS at index 20
Found DOGS at index 25
Found DOGS a total of 4 times
bash
-
4.1$ python hw5_part2.py
Please enter a phrase:
Hello!
Please enter a word to search for:
Good morning
The word cannot be longer than the
phrase.
Please enter a shorter word to search for:
Goodbye
The word cannot be longer than the phrase.
Please enter a shorter word to search for:
ello
Found ello at index 1
Found ello a total of 1 times
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
