我已經編寫了一個代碼以獲取跑步速度值(min/km),將其轉換爲速度(km/hr),然後根據坡度和坡度以及行駛方向是上坡還是下坡計算失速(公里/小時)。新的跑步速度隨着新的跑步速度和你的路線被改變的時間顯示出來。在Python中顯示時間結果的問題
問題是當我輸入3:50(min/km)的速度,上坡坡度爲1%,新跑步速度爲3:60(min/km)時。在這種情況下,如何讓腳本跳到4點?此外,如果輸入3:55(分鐘/公里),則當以4:05(分鐘/公里)讀取時,新的跑步速度爲4:5(分鐘/公里)。我如何編輯這個?
的腳本是:
import math
print('Q1')
SurveyPace = input("Running Pace (min/km): \n "). split(":")
SurveyPace = float(SurveyPace[0])*60 + float(SurveyPace[1])
Speed = 3600/SurveyPace
print("Original running speed =","%.2f" % round(Speed,2), 'km/hr')
print("--------------------------------------------------------")
print('Q2')
SlopeDirection = int(input('For Uphill press 1 \nFor Downhill press 2 \n '))
print("--------------------------------------------------------")
print('Q3')
SlopeGradient = float(input('Percentage gradient(without the % symbol)?\n '))
print("--------------------------------------------------------")
print('CALCULATED RESULTS')
print("--------------------------------------------------------")
if SlopeDirection == 1:
Change = - 0.65 * SlopeGradient
if SlopeDirection == 2:
Change = + 0.35 * SlopeGradient
print ('This route alters your speed by \n', Change,'km/hr')
print("--------------------------------------------------------")
AdjustedSpeed = Speed + Change
AdjustedPace = 3600/AdjustedSpeed
PaceSecs = round(AdjustedPace % 60)
PaceMins = math.floor(AdjustedPace/60)
print("New running speed is \n","%.2f" % round(AdjustedSpeed,2), 'km/hr')
print("--------------------------------------------------------")
print("New running pace is \n", str(PaceMins) + ":" + str(PaceSecs), 'min/km')
print("--------------------------------------------------------")
print("This route alters your pace by \n", int(PaceSecs + (PaceMins*60)) - SurveyPace, "sec/km") #Prints the time change incured
print("--------------------------------------------------------")
感謝
這裏有很多問題,包括我認爲你的邏輯 - 爲什麼「SurveyPace」等於分鐘數乘以60 *加上*公里數?這並不等於什麼。另請參閱Python PEP8風格指南;您使用混合大小寫變量名稱不正確。 – Jeff