First day beginner to python, add to counter after nested loop
jonas.thornvall at gmail.com
jonas.thornvall at gmail.com
Tue Oct 29 14:23:28 EDT 2013
Den tisdagen den 29:e oktober 2013 kl. 19:09:03 UTC+1 skrev Neil Cerutti:
> On 2013-10-29, jonas.thornvall at gmail.com <jonas.thornvall at gmail.com> wrote:
>
> > I have a 25 row javascript that i try to convert to python to get into the language but i run into problem i do not understand howto reach outer loop after finnish inner loop, in fact i do not understand when finished. The javascript i try to conver is below.
>
> >
>
> > #!/usr/bin/python
>
> > import math
>
> > # Function definition is here
>
> > def sq(number):
>
> >
>
> > square=1;
>
> > factor=2;
>
> > exponent=2;
>
> > print(x,"= ");
>
> > while (number>3):
>
> > while (square<=number):
>
> > factor+=1;
>
> > square=math.pow(factor,exponent);
>
> > ----now i want to add conter when loop finished, no end like basic????
>
> > ??? factor--;
>
> > ??? print(factor," ");
>
> > ??? square=math.pow(factor,exponent);
>
> > ??? number=number-(factor*factor);
>
> > ??? square=1;
>
> > ??? factor=1;
>
> > ---here does second loop finish
>
> > return
>
> >
>
> > print("Exp=x^2");
>
> > for x in range (22,23):
>
> > sq(x);
>
> >
>
> >
>
> >
>
> > Here is the javascript with loop i try to convert.
>
>
>
> Output:
>
> 7 = 2 + 3
>
> number square factor exponent
>
> 7 1 2 2
>
> 9 3
>
> 3 1 1
>
>
>
> >
>
> ><HTML>
>
> ><HEAD><TITLE>TEST</TITLE></HEAD>
>
> ><SCRIPT language=Javascript>
>
> > function sq(number){
>
> > square=1;
>
> > factor=2;
>
> > exponent=2;
>
> > document.write(x,"= ");
>
> > while (number>3) {
>
> > while (square<=number) {
>
> > factor++;
>
> > square=Math.pow(factor,exponent);
>
> > }
>
> > factor--;
>
> > document.write(factor," ");
>
> > square=Math.pow(factor,exponent);
>
> > number=number-(factor*factor);
>
> > square=1;
>
> > factor=1;
>
> > }
>
> > document.write("+",number,"<BR>");
>
> > }
>
> > document.write("Exp=x^2<BR>");
>
> > for (x=1;x<100;x++){
>
> > sq(x);
>
> > }
>
> ></script>
>
> ><BODY>
>
> ></BODY>
>
> ></HTML>
>
>
>
> What on does function sq do? Squank? Squarp? Squijel?
>
>
>
> For number 7, I'm thinking I get output:
>
>
>
> 7 = 2 + 3
>
>
>
> --
>
> Neil Cerutti
It write out numbers on modular? square form, just copy past the HTML embedded javascript into text, save as HTML run i brower and you see.
Decimal base
1234=1000+200+30+4 i bad at terminiology but let us call modular base 10 form.
The script convert to modular square form number and write out.
1234= 35 3 +0
35^2 + 3^3 = 1225 + 9 =1234
It is very basic
More information about the Python-list
mailing list