Samrath Chadha
Samrath Chadha

Reputation: 27

How can I use .startswith() in a python function?

def sentence_checker(phrase):
    capital = phrase.capitalize()
    question_words = ('How', 'What', 'Why', 'When', 'Who', 'Which', 'Whose', 'Whom')
    if phrase.startswith(question_words):
         return '{}?'.format(capital)
    else:
        return '{}.'.format(capital)

while True:
    sentence = input('Say Something: ')
    sentence = sentence
    if sentence == '\end':
        break
    else:
        listlist.append(sentence_checker(sentence))

print(' '.join(listlist))

I am a beginner in python. This code recognises all the words except 'How'. This is the output:

Say Something: how
Say Something: \end
How.

Upvotes: 0

Views: 80

Answers (1)

Mr Felix U
Mr Felix U

Reputation: 335

In fact, the only was problem was indeed (as commented) that you were using phrase, rather than capital.

Upvotes: 1

Related Questions