2017-09-29 69 views
-3

我目前正在尝试执行此操作,但我的书中没有显示与布尔变量或与此问题相关的任何内容。我一直在网上查找一段时间,一切都太复杂了,根据单位应该很简单。如果解决方案在这里发布,输入的内容是什么?也许我需要重述一下我的问题。将句子的第二个单词与变量相关联。 (Python)

https://i.stack.imgur.com/RMSEx.png

+0

是的,这个问题需要大量的工作。从[问]开始。我们不知道你在说什么书,或者你的任务是什么,你正在学习什么,或者其他什么。另外,我不知道你为什么引用布尔变量,图像或文本中没有任何暗示。 –

回答

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

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

print("second word is:", secondWord) 
+0

我很感激!答案结束了: secondWord = sentence.split('')[1] –

相关问题