Reputation: 31
I wanted to create a program which understands the famous quote you write and shows the words which have a first letter higher than "g" but I constantly ran into some complications. Here is 2 codes I tried:
So here is my first code;
quote=input("Please input your quotes sentence.")
word=""
for letter in quote:
if word=="":
word=word+letter
elif word.lower().isalpha():
word=word+letter
elif word.lower().isalpha()==False:
if word[0].lower()>="h":
print(word.upper())
word=""
else:
word=""
And my second code;
for letter in quote:
if letter.lower().isalpha():
word=word+letter.lower()
elif letter.lower().isalpha()==False:
if letter.lower()>= "h":
print(word.upper())
word=""
elif letter.lower()<"h":
word=""
Upvotes: 2
Views: 254
Reputation: 542
Juliusmh was near, but not exactly what you wanted. As you wanted the whole word to be printed out (not just the first letter thats before G), here you go:
# Input your quote here
quote = "A very import quote goes here"
out = "" # The output buffer
# Iterate over all words (seperated by <<space>>)
for word in quote.split(" "):
if word[0].lower() < "g": out += quote + " "
print (out)
Upvotes: 1
Reputation: 31
Okay, after chromaerrors answer, i changed the variable "quote" in the 7th column to word and my problem has been solved. The code is this:
quote = input("A very import quote goes here")
out = [] # The output buffer
# Iterate over all words (seperated by <<space>>)
for word in quote.split(" "):
if word[0].lower() < "g": out += word + " "
print ("".join(out))
And the output lists all the words which have starting letter lower than g.
Thanks for all the help. :)
Upvotes: 1
Reputation: 467
Im not sure if I understand your question right, but what about something like this:
# Input your quote here
quote = "A very import quote goes here"
out = [] # The output buffer
# Iterate over all words (seperated by <<space>>)
for word in quote.split(" "):
if word[0].lower() < "g": out += [word]
print (" ".join(out))
Above code will print "A" because its the only word that starts with a letter smaller than "g".
Upvotes: 1