我的个人项目有问题,我的python技能非常基础,但如果有任何帮助,我将不胜感激
问题: 任务1 为了模拟所需的监测,编写一个例程,允许输入婴儿的体温 摄氏度。例行程序还应检查温度是否在可接受范围内 高或过低,并在每种情况下输出适当的消息。 任务2 编写另一个例程,将三小时内的温度存储在数组中。这 例行程序应输出最高和最低温度,并计算它们之间的差异 温度。 注:更多强调任务2
我失败的尝试:
from array import array
print("BABY TEMPERATURE CHECKER")
MinBbyTemp = float(36.0)
MaxBbyTemp = float(37.5)
routTemp = array("i", [])
BabyTemp = float(input("What is the temperature of the baby?"))
if BabyTemp < MinBbyTemp:
print("The temperature of the baby is low/unusual and needs to be worked on")
elif BabyTemp > MaxBbyTemp:
print("The temperature of the baby is too high and above the average")
else:
print("The temperature inputted is out of range")
首先,我建议使用Pythons内置的列表类型,而不是数组。 其次,
float(36.0)
是多余的,因为Python会将36.0
推断为浮点您的代码实际上相当不错,但如果您想输入多个值,则需要一个循环。这个循环将永远持续下去,因此如果您希望它结束,您需要将
while True
更改为while some_boolean
,并让用户更改some_boolean
或for
循环执行此循环后,将有一个Python温度列表,您可以将其处理为Daniel Hao explained.
@EmeluDev-让我们试着一步一步解决这个问题。假设你已经收集了每日温度。测量已完成(任务1已完成)。然后从任务2开始:
我会这样做:
相关问题 更多 >
编程相关推荐