java to python
Martin Franklin
mfranklin1 at gatwick.westerngeco.slb.com
Fri Nov 8 10:31:35 EST 2002
On Fri, 2002-11-08 at 15:17, Christian Stockhammer wrote:
> Hello List!
>
> I've got homework I have to solve in python but i just know a little bit
> java and i got my homework to run in java. Is there anybody who can help me
> to translate that code to python?
>
> Here it is:
>
> public class Tilgung{
> public static void main(String [] args){
> tilgungsplan(100000.0,5.0,20000.0);
> }
>
> static void tilgungsplan(double schuld,double zinsfaktor,double tilgung){
> double zinsen;
> double echteTilgung;
>
> System.out.println("Periode Restschuld Zinsen Tilgung");
>
> for(int i=0;i<5;i++){
> zinsen=(schuld*zinsfaktor)/100;
> echteTilgung=tilgung-zinsen;
> System.out.println(" "+i+" "+schuld+" "+zinsen+" "+echteTilgung);
> schuld=schuld-echteTilgung;
> }
> System.out.println(" Restzahlung: "+schuld);
> }
> }
>
> This is what it produces: (it is a calculator for paying back a credit)!!!
> Periode Restschuld Zinsen Tilgung
> 0 100000.00 5000.00 15000.00
> 1 85000.00 4250.00 15750.00
> 2 69250.00 3462.50 16537.50
> 3 52712.50 2635.63 17364.38
> 4 35348.13 1767.41 18232.59
> Restzahlung: 17115.53
>
> Is there anybody who is willing to help me. I really appreciate any
> suggestions
>
> Cheers Christian
>
>
Some translations for you to get started:
JAVA: System.out.println("");
Python: print ""
JAVA: for(int i=0;i<5;i++)
Python: for i in range(5):
JAVA: static void tilgungsplan(double schuld,double zinsfaktor,double
tilgung)
Python: def tilgungsplan(schuld, zinsfaktor, tilgung):
Otherwise make sure you indent coerrectly and get rid of those
semicolons! (;)
Now go grab a copy of the Python tutorial:-
http://www.python.org/doc/current/tut/tut.html
HTH
Martin
More information about the Python-list
mailing list