我的代码/项目:我正在学习Python,并试图为某些马拉松训练创建一个速度计算器。解析一个整数的小数点
我的问题:如何从计算出的最终数字中分离/解析小数?
例:使用以下输入值 #[Minutes, Seconds, Distance in miles] [17, 37, 3.1] #17 * 60 = 1020; 1020 + 37 = 1057; 1057/3.1 = 340.96
整个代码会给我的340.96秒一个答案。如果我把它除以60来找出确切的分钟数/秒;答案变成了5.68。
我需要把这个“.68”乘以60来得到实际秒数,因为它代表了一分钟的68%。
recordMinutes = int(input("What is your total minutes? "))
for steps in range(1):
converted = recordMinutes * 60
recordSeconds = int(input("What is your total seconds leftover? "))
for steps in range(1):
combined = converted + recordSeconds
distance = float(input("What is the distance? "))
paceRaw = combined/distance
paceBasic = (paceRaw/60)
#This is where I would multiply the ".68" by 60
pace = (#decimal remainder * 60) + #whole number
print ("You need to run %d per mile " % pace)
我同意,谢谢!很显然,我想成为一个“懒惰”的程序员,但我发现通过解构每一步,我可以更好地学习。 – adamcasey
当然,很高兴帮助你。还请考虑标记此答案,以便关闭该主题。 – Hisagr