函数Return的句子输出后怎么样操作可以让句子带上引号?
各位大侠,想请教一个简单的问题。下面这个函数Return后怎么才能让Return后面的句子带上引号输出,谢谢!
def calculateWeight(mass, planet="Earth", gravity=9.807):
weight = mass*gravity
roundedWeight = round(weight, 2)
return "A " + str(mass) + " kg object weighs " + str(roundedWeight) + " Newtons on " + planet + "."
print(calculateWeight(10.0))
print(calculateWeight(5.0, planet="Jupiter", gravity=24.79))
不知道怎么改一下让这两个句子输出后都带引号,下面这样!
”A 10.0 kg object weighs 98.07 Newtons on Earth.“
”A 5.0 kg object weighs 123.95 Newtons on Jupiter.“
多谢出手相助!
David >>> x = '"' + '中间的字符串' + '"'
>>> print(x)
"中间的字符串" print('"' + calculateWeight(10.0) + '"')
print('"' + calculateWeight(5.0, planet="Jupiter", gravity=24.79) + '"') jackz007 发表于 2022-11-1 09:20
非常好用,多谢,大侠。
页:
[1]