Program: Words after “G”/“g”
Create a program inputs a phrase (like a famous quotation) and prints all of the words that start with h-z
Sample input:
enter a 1 sentence quote, non-alpha separate words: Wheresoever you go, go with all your heart
Sample output:
WHERESOEVER
YOU
WITH
YOUR
HEART
- split the words by building a placeholder variable:
word- loop each character in the input string
- check if character is a letter
- add a letter to
wordeach loop until a non-alpha char is encountered
-
if character is alpha
- add character to
word - non-alpha detected (space, punctuation, digit,…) defines the end of a word and goes to
else
- add character to
-
else- check
ifword is greater than “g” alphabetically- print word
- set word = empty string
- or else
- set word = empty string and build the next word
- check
Hint: use .lower()
I only have the follows:
phrase = "Wheresoever you go, go with all your heart"
word = ""
start = 0
space = phrase.find(" ")
while space != -1:
print(phrase[start:space])
start = space + 1
space = phrase.find(" ", space + 1)
How to do the rest? Please help!
… Anyways, good luck on your homework!!