First day beginner to python, add to counter after nested loop

jonas.thornvall at gmail.com jonas.thornvall at gmail.com
Wed Oct 30 05:52:30 EDT 2013


Den onsdagen den 30:e oktober 2013 kl. 10:48:36 UTC+1 skrev jonas.t... at gmail.com:
> Den onsdagen den 30:e oktober 2013 kl. 09:52:16 UTC+1 skrev jonas.t... at gmail.com:
> 
> > Den onsdagen den 30:e oktober 2013 kl. 08:07:31 UTC+1 skrev Tim Roberts:
> 
> > 
> 
> > > jonas.thornvall at gmail.com wrote:
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >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.  
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > You only say that because your brain has been poisoned by languages that
> 
> > 
> 
> > > 
> 
> > 
> 
> > > require some kind of "end".  It's not necessary, and it's extra typing. 99%
> 
> > 
> 
> > > 
> 
> > 
> 
> > > of programmers do the indentation anyway, to make the program easy to read,
> 
> > 
> 
> > > 
> 
> > 
> 
> > > so why not just make it part of the syntax?  That way, you don't
> 
> > 
> 
> > > 
> 
> > 
> 
> > > accidentally have the indentation not match the syntax.
> 
> > 
> 
> > > 
> 
> > 
> 
> > > -- 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > Tim Roberts, timr at probo.com
> 
> > 
> 
> > > 
> 
> > 
> 
> > > Providenza & Boekelheide, Inc.
> 
> > 
> 
> > 
> 
> > 
> 
> > It maybe common practice in program languages, but to me it is slightly confusing to have the while/for loop on the same indent level, as the regular statements.
> 
> > 
> 
> > Because when the while loop ends there is no other identification then that the indent stopped, and to me it is easy to interpret that terms that actually straight under the loop belongs to it.
> 
> > 
> 
> > 
> 
> > 
> 
> > But of course it is a matter of adjust the way i look at the code.
> 
> > 
> 
> > Thanks for help guys.
> 
> 
> 
> To show you guys that i am not totally uneducable i actually followed your sugestions ;D. 
> 
> (Is there any support similar javascript canvas for drawing, and HTML for interactivity, textbox, buttons in python?). 
> 
> 
> 
> I have been programming some PHP long time ago, basicly only remember you had to have a server running to interact via HTML. 
> 
> 
> 
> #!/usr/bin/python
> 
> import math
> 
> # Function definition is here
> 
> def sq(number):
> 
>    
> 
>       square=1
> 
>       factor=2
> 
>       multip=exponent*exponent
> 
>       print(x,"= ", end="")
> 
>       while number>=multip:
> 
>          while square<=number:
> 
>             factor+=1
> 
>             square=factor*factor
> 
>          factor-=1	
> 
>          print(factor,"^2+",sep="",end="")
> 
>          square=factor*factor
> 
>          number=number-(factor*factor)
> 
>          square=1
> 
>          factor=1
> 
>       print(number)
> 
> 
> 
> #Set exponent here      
> 
> exponent=3
> 
> print("Exp=x^",exponent,sep="")
> 
> #Set range of numbers x
> 
> for x in range (1,100):
> 
>       sq(x);

Forgot change the static square that was written out, i am a bit undecuable afterall...

#!/usr/bin/python
import math
# Function definition is here
def sq(number):
   
      square=1
      factor=2
      multip=exponent*exponent
      print(x,"= ", end="")
      while number>=multip:
         while square<=number:
            factor+=1
            square=factor*factor
         factor-=1	
         print(factor,"^",exponent,"+",sep="",end="")
         square=factor*factor
         number=number-(factor*factor)
         square=1
         factor=1
      print(number)

#Set exponent here      
exponent=3
print("Exp=x^",exponent,sep="")
#Set range of numbers x
for x in range (1,100):
      sq(x);



More information about the Python-list mailing list