J
jonas.thornvall
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.
<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>
#!/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.
<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>