-3
請幫助我,我正在嘗試編寫一個PYTHON代碼,它使用名爲calcExcelDate的已定義函數來實現某些給定日期的excel日期等效方程:使用已定義的函數來實現某些方程式
- year(4位整數從1900到9999);
- month(從1到12的1或2位整數);
- 天(從1到31的1或2位整數,取決於月份)。
我定義了函數,並使用了3個循環來指定上述給定的年,月和日的範圍。但是,如何才能使用該功能來實現follwoing公式:
y_2 = year - 1900
em = math.floor((14 - month)/12)
y_3 = y_2 - em
m_2 = month + 12 * em
I_ = 1 + min(y_3, 0) + math.floor(y_3/4) - math.floor(y_3/100) + math.floor((y_3 + 300)/400)
d_1 = math.floor(-1.63 + (m_2 - 1) * 30.6)
d_2 = day + y_3 * 365 + I_ + d_1
我迄今爲止代碼:
import time
import math
DAYS = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
FULL_MONTHS = ("January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December")
mm_ = tuple(str(date) for date in range(2013-10-17, 2100-01-01)) # a tuple of character strings containing dates in the date range Excel supports,
# such as ("2013-Oct-17", "2100-01-01")
print mm_
def calcExcelDate(year, month, day):
for year in range(1900, 10000):
for month in range(1, 13):
for day in range(1, 32):
y_2 = year - 1900
em = math.floor((14 - month)/12)
y_3 = y_2 - em
m_2 = month + 12 * em
I_ = 1 + min(y_3, 0) + math.floor(y_3/4) - math.floor(y_3/100)
+ math.floor((y_3 + 300)/400)
d_1 = math.floor(-1.63 + (m_2 - 1) * 30.6)
d_2 = day + y_3 * 365 + I_ + d_1
xx_ = calcExcelDate(2010, 10, 1)
print xx_
到底在期待什麼從'calcExcelDate輸出(2010 ,10,1)'?我不認爲你需要循環所有'year' /'month' /'day'(尤其是因爲它只是覆蓋了你傳入函數的'year' /'month' /''日)。所以刪除三個for循環可能是第一步,只是離開方程組,但我不知道你想要返回什麼。 'd_2'包含你想要的最終答案嗎? –
同意。 「功能」一詞通常意味着輸入和輸出之間的某種關係。它看起來像輸入將是某個日期。你想要的輸出是什麼?有什麼具體的例子**你已經手工檢查你的代碼是否正在計算你期望的值? – dyoo