Mortgage calculator











up vote
0
down vote

favorite












my aim is to create mortgage calculator in python. I want it to calculate number of days between now, and fixed time in future. To get number od days, or months between two dates I use datetime , that you can see in my code. My problem is that i can't perform division operation on number of days returned by datetime function, because it is in wrong data type. Is there any option to change date type into integer?



import datetime
from datetime import date
import time


today=datetime.date.today()
d0=date(2021,11,29)
delta=d0-today
print(delta.days)

def diff_month(d1,d2,c1):
if c1=="monthly":
a=(d1.year - d2.year) * 12 + d1.month - d2.month
instalment = 1000000 / a

return (instalment)
if c1=="daily":
a=(d1-d2)
instalment=1000000/a.days

return (instalment)




# counter=diff_month(d0,today,"daily")
#instalment=1000000/counter
#print(type(counter))
#print(instalment)
print(diff_month(d0,today,"daily"))


Thanks in advance
edit:
Thanks for your advices, finally i do that in this way. The only problem is that monnthly payment is equal everytime, in reality it would not be equal, because number of days in each month is not constant, so i would rather use daily payment than monthly.










share|improve this question




















  • 2




    But you do that correctly in your test before the function: call .days on the timedelta object.
    – Daniel Roseman
    Nov 19 at 15:07















up vote
0
down vote

favorite












my aim is to create mortgage calculator in python. I want it to calculate number of days between now, and fixed time in future. To get number od days, or months between two dates I use datetime , that you can see in my code. My problem is that i can't perform division operation on number of days returned by datetime function, because it is in wrong data type. Is there any option to change date type into integer?



import datetime
from datetime import date
import time


today=datetime.date.today()
d0=date(2021,11,29)
delta=d0-today
print(delta.days)

def diff_month(d1,d2,c1):
if c1=="monthly":
a=(d1.year - d2.year) * 12 + d1.month - d2.month
instalment = 1000000 / a

return (instalment)
if c1=="daily":
a=(d1-d2)
instalment=1000000/a.days

return (instalment)




# counter=diff_month(d0,today,"daily")
#instalment=1000000/counter
#print(type(counter))
#print(instalment)
print(diff_month(d0,today,"daily"))


Thanks in advance
edit:
Thanks for your advices, finally i do that in this way. The only problem is that monnthly payment is equal everytime, in reality it would not be equal, because number of days in each month is not constant, so i would rather use daily payment than monthly.










share|improve this question




















  • 2




    But you do that correctly in your test before the function: call .days on the timedelta object.
    – Daniel Roseman
    Nov 19 at 15:07













up vote
0
down vote

favorite









up vote
0
down vote

favorite











my aim is to create mortgage calculator in python. I want it to calculate number of days between now, and fixed time in future. To get number od days, or months between two dates I use datetime , that you can see in my code. My problem is that i can't perform division operation on number of days returned by datetime function, because it is in wrong data type. Is there any option to change date type into integer?



import datetime
from datetime import date
import time


today=datetime.date.today()
d0=date(2021,11,29)
delta=d0-today
print(delta.days)

def diff_month(d1,d2,c1):
if c1=="monthly":
a=(d1.year - d2.year) * 12 + d1.month - d2.month
instalment = 1000000 / a

return (instalment)
if c1=="daily":
a=(d1-d2)
instalment=1000000/a.days

return (instalment)




# counter=diff_month(d0,today,"daily")
#instalment=1000000/counter
#print(type(counter))
#print(instalment)
print(diff_month(d0,today,"daily"))


Thanks in advance
edit:
Thanks for your advices, finally i do that in this way. The only problem is that monnthly payment is equal everytime, in reality it would not be equal, because number of days in each month is not constant, so i would rather use daily payment than monthly.










share|improve this question















my aim is to create mortgage calculator in python. I want it to calculate number of days between now, and fixed time in future. To get number od days, or months between two dates I use datetime , that you can see in my code. My problem is that i can't perform division operation on number of days returned by datetime function, because it is in wrong data type. Is there any option to change date type into integer?



import datetime
from datetime import date
import time


today=datetime.date.today()
d0=date(2021,11,29)
delta=d0-today
print(delta.days)

def diff_month(d1,d2,c1):
if c1=="monthly":
a=(d1.year - d2.year) * 12 + d1.month - d2.month
instalment = 1000000 / a

return (instalment)
if c1=="daily":
a=(d1-d2)
instalment=1000000/a.days

return (instalment)




# counter=diff_month(d0,today,"daily")
#instalment=1000000/counter
#print(type(counter))
#print(instalment)
print(diff_month(d0,today,"daily"))


Thanks in advance
edit:
Thanks for your advices, finally i do that in this way. The only problem is that monnthly payment is equal everytime, in reality it would not be equal, because number of days in each month is not constant, so i would rather use daily payment than monthly.







python date






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 17:02

























asked Nov 19 at 15:06









Marcin

208




208








  • 2




    But you do that correctly in your test before the function: call .days on the timedelta object.
    – Daniel Roseman
    Nov 19 at 15:07














  • 2




    But you do that correctly in your test before the function: call .days on the timedelta object.
    – Daniel Roseman
    Nov 19 at 15:07








2




2




But you do that correctly in your test before the function: call .days on the timedelta object.
– Daniel Roseman
Nov 19 at 15:07




But you do that correctly in your test before the function: call .days on the timedelta object.
– Daniel Roseman
Nov 19 at 15:07












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










Some suggestions:



On the line:



instalment=1000000/counter


You expect counter to contain the number of days. However, diff_month returns the number of months if c1 is "monthly". Fix this. make the function return the number of days in all cases.



The return value from diff_month is of type timedelta. Objects of this type have an attribute called days which is an integer, so you can write:



instalment=1000000/counter.days





share|improve this answer





















  • I suggest that instead of writing all your code in the comment, edit the original question and add a section about your changes. Code in the comment is barely readable
    – Yakov Dan
    Nov 19 at 16:55











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377447%2fmortgage-calculator%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










Some suggestions:



On the line:



instalment=1000000/counter


You expect counter to contain the number of days. However, diff_month returns the number of months if c1 is "monthly". Fix this. make the function return the number of days in all cases.



The return value from diff_month is of type timedelta. Objects of this type have an attribute called days which is an integer, so you can write:



instalment=1000000/counter.days





share|improve this answer





















  • I suggest that instead of writing all your code in the comment, edit the original question and add a section about your changes. Code in the comment is barely readable
    – Yakov Dan
    Nov 19 at 16:55















up vote
0
down vote



accepted










Some suggestions:



On the line:



instalment=1000000/counter


You expect counter to contain the number of days. However, diff_month returns the number of months if c1 is "monthly". Fix this. make the function return the number of days in all cases.



The return value from diff_month is of type timedelta. Objects of this type have an attribute called days which is an integer, so you can write:



instalment=1000000/counter.days





share|improve this answer





















  • I suggest that instead of writing all your code in the comment, edit the original question and add a section about your changes. Code in the comment is barely readable
    – Yakov Dan
    Nov 19 at 16:55













up vote
0
down vote



accepted







up vote
0
down vote



accepted






Some suggestions:



On the line:



instalment=1000000/counter


You expect counter to contain the number of days. However, diff_month returns the number of months if c1 is "monthly". Fix this. make the function return the number of days in all cases.



The return value from diff_month is of type timedelta. Objects of this type have an attribute called days which is an integer, so you can write:



instalment=1000000/counter.days





share|improve this answer












Some suggestions:



On the line:



instalment=1000000/counter


You expect counter to contain the number of days. However, diff_month returns the number of months if c1 is "monthly". Fix this. make the function return the number of days in all cases.



The return value from diff_month is of type timedelta. Objects of this type have an attribute called days which is an integer, so you can write:



instalment=1000000/counter.days






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 15:19









Yakov Dan

381111




381111












  • I suggest that instead of writing all your code in the comment, edit the original question and add a section about your changes. Code in the comment is barely readable
    – Yakov Dan
    Nov 19 at 16:55


















  • I suggest that instead of writing all your code in the comment, edit the original question and add a section about your changes. Code in the comment is barely readable
    – Yakov Dan
    Nov 19 at 16:55
















I suggest that instead of writing all your code in the comment, edit the original question and add a section about your changes. Code in the comment is barely readable
– Yakov Dan
Nov 19 at 16:55




I suggest that instead of writing all your code in the comment, edit the original question and add a section about your changes. Code in the comment is barely readable
– Yakov Dan
Nov 19 at 16:55


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377447%2fmortgage-calculator%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Tonle Sap (See)

I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

Guatemaltekische Davis-Cup-Mannschaft