如何解决创建一个程序,根据某些天的温度计算分配给供暖和制冷房屋的天数
我创建了一个程序,该程序根据某些天的温度来计算委派给采暖和制冷房屋的天数。如果温度> 80,则将其指定为冷却日,如果温度
def main():
day = 1
C_days = 0
H_days = 0
done = False
while not done:
temp = input("Please enter the average temperature for day " + str(day) + " or stop to end: ")
if temp.lower() != "stop" and temp.lower() != "s":
temp = eval(temp)
if temp > 80:
C_days += temp-80
elif temp < 60:
H_days += 60-temp
day += 1
else:
done = True
print("The number of heating-degree days: ",H_days)
print("The number of cooling-degree days: ",C_days)
main()
解决方法
尝试将代码更改为此
def main():
day = 1
C_days = 0
H_days = 0
done = False
while not done:
temp = input("Please enter the average temperature for day " + str(day) + " or stop to end: ")
#checks if it's supposed to stop or not
if temp.lower() != "stop" and temp.lower() != "s":
temp = eval(temp)
if temp > 80:
#here is a change,since you want the total number of days,#you just have to add one to the cooling days if it's more than 80
C_days = C_days + 1
elif temp < 60:
#and here is a change,#you just have to add one to the heating days if it's more than 80
H_days = H_days + 1
day += 1
else:
done = True
print("The number of heating-degree days: ",H_days)
print("The number of cooling-degree days: ",C_days)
main()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。