试图将除法方程的结果放到小数点后两位?



所以我只是为加拿大的 Covid 死亡做了一个简单的文件,我可以;似乎在除法后将小数位降低到两个?

import datetime as dt
start_date = dt.date(2020, 3, 9)
end_date = dt.date(2020, 5, 18)
date_td = end_date - start_date
days_between = date_td.days
print(days_between, 'Days since first Covid death in Canada')
# March 3, 2020 was first recorded death in Canada.  70 days
total_deaths = 5805 / 70
print(total_deaths,':' 'Total Deaths in Canada per day')
carehome_deaths = 4702 / 70
print(carehome_deaths,':' 'Total Care Home deaths per day')
outside_deaths = 1103 / 70
print(outside_deaths,':' 'Total deaths outside of care homes per day')

输出:

自加拿大首次 Covid 死亡以来 70 天 82.92857142857143 :加拿大每天的总死亡人数 67.17142857142858 :每日全护理院死亡人数 15.757142857142858 :每天在养老院外的总死亡人数

要在 print 语句中舍入小数,请执行以下操作:

print(round(total_deaths, 2), "....")

您可以在此处找到有关内置数据类型的更多信息 round((

使用round(total_deaths, 2),希望这有帮助!

相关内容

  • 没有找到相关文章

最新更新