計算應收帳款(debtors)
當我們以賒帳方式銷售時,賒銷的那一部分會列在資產負債表的「應收帳款」或「Debtors」之下。舉例來說,若 1 月發生賒銷且回收期為 60 天,該筆金額會在 1 月記入「Debtors」科目,但要到 3 月才會收現(結清),以此類推。
在這個練習中,我們會建立下列清單:
- 當月的賒銷金額
credits,在本練習中為銷售金額的 60%。 - 應收帳款總額
debtors,計算方式為:當月的賒銷金額,加上前一個月的賒銷金額,減去前兩個月的賒銷金額(因為我們假設 2 個月前、也就是 60 天前的賒銷,到了現在會回收)。
我們已為變數 month 設定了索引。month 的起始值為 0。
本練習屬於課程
使用 Python 進行財務預測
練習說明
建立空白的
credits清單與空白的debtors清單。完成
for迴圈:- 將銷售金額(指定為變數
mvalue)乘上賒銷比例(60%),計算當月的賒銷金額。 - 如果
month大於 0,將「當月賒銷金額加上前一個月的賒銷金額」加入debtors。 - 如果
month不大於 0,將「當月賒銷金額」加入debtors。
- 將銷售金額(指定為變數
印出
debtors清單。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create the list for sales, and empty lists for debtors and credits
sales = [500, 350, 700]
____ = []
____ = []
# Create the statement to append the calculated figures to the debtors and credits lists
for mvalue in sales:
credits.append(mvalue * ____)
if month > 0:
____.append(credits[____] + credits[month-1])
else:
____.append(credits[____])
month += 1
# Print the result
print("The ‘Debtors’ are {}.".format(_____))