【发布时间】:2014-10-06 00:59:21
【问题描述】:
我想用 find 功能解决这个问题。我一直在使用 split 函数来处理它,因为我不明白 find 。如果有人能告诉我如何用 find 来做,那就太棒了。我也陷入了这部分问题。
start = ("Please enter the starting weight of food (in lbs:ozs) = ")
answerOne = input(start).strip()
startPounds, startOunces = answerOne.split(":")
startPounds = int(startPounds)
startOunces = int(startOunces)
end = "Please enter the ending weight of food (in lbs:ozs) = "
answerTwo = input(end).strip()
endPounds, endOunces = answerTwo.split(":")
endPounds = int(endPounds)
endOunces = int(endOunces)
startPoundsO = startPounds * 16
endPoundsO = endPounds * 16
poundsO = startPoundsO - endPoundsO
这是我遇到问题的地方。
这是原来的问题。
一只猴子正在被喂一些食物。阅读以磅为单位的起始重量:盎司。还要以 lbs:ozs 为单位读取最终重量(您可以假设这小于起始重量。找出差异并打印出猴子以 lbs:ozs 为单位消耗的食物量。
这是提供的数据。
食物起始重量(磅:盎司)=8:9
食物的最终重量(磅:盎司)=6:14
猴子消耗的食物 (lbs:ozs)=1:11
【问题讨论】:
-
split非常适合这个。为此使用find就像使用剪线钳准备生菜一样。你可以做到,但很尴尬。
标签: python python-3.x split find