Homework help Please!

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 word each 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
  • else
    • check if word is greater than “g” alphabetically
      • print word
      • set word = empty string
    • or else
      • set word = empty string and build the next word

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!

What language are you writing this in? I can’t really find a context here, because there is hints saying that this is a Python code, and there is hints that points that this is JavaScript.

I am writing a Python 3 code.

1 Like

Hey @Amelie,

I’m sorry, I can’t really help with Python. I haven’t learned the language yet. But I’m sure there are other people that can help you. Sorry I couldn’t help you :frowning:… Anyways, good luck on your homework!!

Hi Catalactics, No problem. Thank you for trying to help!

1 Like