Yanni Asimacopoulos Yanni Asimacopoulos - 3 years ago 64
Python Question

Associating the second word of a sentence to a variable. (Python)

I'm currently trying to perform this, but my book for class doesn't show anything in relation to Boolean variables or anything related to this problem. I've been looking online for a while and everything is way too complicated for something that should be simple according the unit. If the solution is posted here, what was typed in to find it? Maybe I need to rephrase my question.


Answer Source
def getSecondWord(sentence):
    res = sentence.split(' ')[1]
    if res.endswith('.'):
        return res[:-1]
        return res

inputSentence = 'broccoli is delicious'
secondWord = getSecondWord(inputSentence)

print("second word is:", secondWord)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download