First day beginner to python, add to counter after nested loop
jonas.thornvall at gmail.com
jonas.thornvall at gmail.com
Tue Oct 29 16:08:39 EDT 2013
Den tisdagen den 29:e oktober 2013 kl. 20:24:57 UTC+1 skrev Dave Angel:
> On 29/10/2013 14:35, jonas.thornvall at gmail.com wrote:
>
>
>
> (Deleting hundreds of quad-spaced garbage. Please be more considerate
>
> of others if you choose to use buggy googlegroups, maybe starting by
>
> studying:
>
>
>
> )
>
>
>
> Please indent by 4 columns, not 1. Since indentation is how scope is
>
> specified in Python, it's very important to get it right.
>
>
>
> > i do not understand howto reach outer loop after finnish inner loop, in fact i do not understand when finished.
>
>
>
> The inner loop is finished whenever you stop indenting by 8 columns. If
>
> you have a fundamental problem like this, keep it simple till you
>
> understand it:
>
>
>
>
>
> q = 12
>
> for x in range(10):
>
> for y in range(3):
>
> q = 3*q + 1
>
> print("inner", q)
>
> print("outer", x*q)
>
>
>
> print("done")
>
>
>
> Because of the detenting, the print("outer", x*q) is in the outer loop.
>
>
>
>
>
> --
>
> DaveA
Why did Python not implement end... The end is really not necessary for the programming language it can be excluded, but it is a courtesy to the programmer and could easily be transformed to indents automaticly, that is removed before the compiliation/interpretation of code.
Got the script working though :D, good start. It seem though that Python automaticly add linebreaks after printout. Is there a way to not have print command change line? Or must i build up a string/strings for later printout?
#!/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);
factor-=1;
print(factor,"^2");
square=math.pow(factor,exponent);
number=number-(factor*factor);
square=1;
factor=1;
print("+",number);
return
print("Exp=x^2");
for x in range (21,22):
sq(x);
More information about the Python-list
mailing list