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:35:12 EDT 2013
Den tisdagen den 29:e oktober 2013 kl. 19:23:28 UTC+1 skrev jonas.t... at gmail.com:
> 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
And it work for any exponential form square, cubic etc. I want to implement in python since javascript lack bignumb, and diskread write function.
Exp=x^2
7777777777= 88191 353 26 3 +2
Exp=x^3
7777777777= 1981 153 33 10 4 3 3 +4
Exp=x^4
7777777777= 296 100 33 12 9 5 4 3 3 2 2 2 +12
Exp=x^5
7777777777= 95 33 15 9 6 5 5 3 3 2 2 +9
Exp=x^6
7777777777= 44 28 18 13 9 7 6 5 5 4 3 3 3 3 2 2 2 2 2 2 2 2 +64
Exp=x^7
7777777777= 25 20 16 14 11 7 5 4 3 3 3 2 2 2 2 2 2 2 2 2 2 +128
Exp=x^8
7777777777= 17 12 11 10 9 7 7 6 5 5 5 4 4 4 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 +33
Exp=x^9
7777777777= 12 11 8 7 7 7 5 5 4 4 4 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 +510
Exp=x^10
7777777777= 9 9 7 7 6 6 6 5 5 5 5 5 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 +502
Exp=x^11
Here is code for doing it for any exponent.
<HTML>
<HEAD><TITLE>TEST</TITLE></HEAD>
<SCRIPT language=Javascript>
function sq(number,exponent){
exp=1;
factor=2;
multip=Math.pow(2,exponent);
document.write(x,"= ");
while (number>multip){
while (exp<=number)
{ factor++;
exp=Math.pow(factor,exponent);
}
factor--;
document.write(factor," ");
exp=Math.pow(factor,exponent);
number=number-Math.pow(factor,exponent);
exp=1;
factor=1;
}
document.write("+",number,"<BR>");
}
//Set exponent by change y
y=10;
x=7777777777
for (y=2;y<20;y++){
document.write("Exp=x^",y,"<BR>");
sq(x,y);
}
</script>
<BODY>
</BODY>
</HTML>
More information about the Python-list
mailing list