python-3.x - 格式化总数,使其不显示小数位
问题描述
所以,我试图让这段代码最后(总计)不显示任何小数位......但我真的找不到办法做到这一点。有没有办法做到这一点而不必重写一切?
test1_weight = float(input("Type your 1st Test weight: "))
test2_grade = float(input("Type your 1st Test grade: "))
test2_weight = float(input("Type your 1st Test weight: "))
total = (test1_grade * test1_weight + test2_grade * test2_weight)/(test1_weight + test2_weight)
print ("The weighted average is: ", total)
解决方案
您可以total
转换为整数:
total = int(total)
例如:
total = 3.75
total = int(total)
print(total) # 3
推荐阅读
- swift - SceneKit 材质闪烁
- asp.net - Crystal Report 只打印第一页,第二页为空白
- c# - 添加迁移不适用于 MySQL
- node.js - 获取邀请人
- c# - 在给定字符串中查找唯一出现的 _
- python - 在python中将一些数组合并到单个数组/列表中
- java - Spring boot 考虑定义一个 bean 类型
- c# - 如何获取所有正在运行的 Chrome 实例
- angular - Angular/Typescript - 在两个相似对象之间分配对象属性的快速方法
- google-cloud-platform - 我们可以同时在同一数据上运行多个谷歌云管道吗?