[Tutor] Calaculating a monthly total of earning

Alan Gauld alan.gauld at btinternet.com
Mon Jan 17 01:32:45 CET 2011


"walter weston" <hacker0100 at hotmail.com> wrote

> def income_report(yearly_income,hourly_income):
>    sum_of_monthly=int(yearly_income/12)# his yearly income dividing 
> by 12.
>     minus_weekends=hourly_income*64
>     total_income=int(minus_weekends-sum_of_monthly)
>     return sum_of_monthly,total_income

When you divide you get a decimal result which you then convert
to an integer - a whole number - so you lose the fractional part.
When you multiply by 12 you get 12 times the integer not the
original number.

And for total_income shouldn't the subraction be the other way around?

> Python is so tempormential what is wrong with my code?

Python is not temperamental, it is just doing exactly what you ask it 
to do.
It makes no judgement about whether what you are asking is sensible or 
not.

One of the more humbling things about programming is that you become
accutely aware of your own ability to screw things up! ;-)

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/





--------------------------------------------------------------------------------


> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 




More information about the Tutor mailing list