python - 浮点值到时间(HH:MM)格式
问题描述
hr = int(input("Enter period of earth rotation : "))
ln = float(input("Enter value of longitude : "))
calc = (hr/360)*ln
print (calc)
输入:-24,82.50
我希望输出是5:30
, 而不是5.5
解决方案
您已经得到calc
,以小时为单位的确切时间,您需要将十进制转换为某个分钟数。我会通过分别存储小时和分钟来做到这一点:
hours = int(calc)
minutes = int((calc - hours) * 60)
print(f"{hours}:{minutes:02}")
推荐阅读
- python - 使用 BeautifulSoup 从 svg 中抓取文本
- java - 如何修复 json 搜索
- angular - 将角度组件变量绑定到 CSS 数据属性
- python - Hadamard 在数组列表上的效率
- r - 如何在 R Dataframe 中将每个组的第一个值分配给“1”并剩下“0”
- reactjs - Reactjs 网站图像在 Internet Explorer 中工作,但不是 chrome 或 firefox?
- python - 编译器和解析器,codechef 的错误答案
- swift - 按钮混在一起
- php - 我需要知道我的代码有什么问题,我正在尝试获取与之相关的所有子类别和帖子
- excel - 在多个工作表上拆分数据