关于 python 的家庭作业帮助



如何在python中执行此操作?

您将编写的第一个函数应称为"wordSalad"。您的函数应该需要四 (4( 个参数,所有字符串。该函数应返回一 (1( 个字符串,格式如下:"我爱 和 和 .">

示例测试用例:单词沙拉("鲍勃","乔","柠檬水","披萨"(

返回我喜欢鲍勃和乔的柠檬水和披萨。

def wordSalad(a,b,c,d):
    return "I love "+a+" and "+b+" with "+c+" and "+d+'.'

试试这个。您只需要连接字符串。您也可以使用字符串格式。

def wordSalad(a,b,c,d):
    return 'I love {} and {} with {} and {}.'.format(a,b,c,d)

除了@WHACKAMADOODLE3000的答案之外,您还可以使用 %s。

def wordSalad(a, b, c, d):
    return 'I love %s and %s with %s and %s.' % (a, b, c, d)

最新更新