0
def words():
quote = input("Enter a 1 sentence quote, non-alpha separate words: ")
word = ""
for ltr in quote:
    if ltr.isalpha():
        word = word + ltr
    else:
        if word[0].lower() > "g":
            print(word.upper())
            word = ""
        else:
            word = ""

Here all the info.

Seriously I do not know what to do.

3
  • 1
    Post your full error message. Not a link to it, post the text please. Commented Mar 16, 2018 at 23:17
  • 1
    word[0].lower will throw out the error because word may be empty. Commented Mar 16, 2018 at 23:19
  • @huck_cussler Got it Commented Mar 16, 2018 at 23:31

1 Answer 1

2

Don't use word[0] because word could be empty while still failing the isalpha check. Check for len(word) first:

if len(word) and word[0].lower() > 'g':
Sign up to request clarification or add additional context in comments.

1 Comment

Note: I think you don't even need len(), since non-empty word is truthy. So if word and world[0]... should be sufficient too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.