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

jonas.thornvall at gmail.com jonas.thornvall at gmail.com
Wed Oct 30 10:24:59 EDT 2013


Den onsdagen den 30:e oktober 2013 kl. 11:11:17 UTC+1 skrev jonas.t... at gmail.com:
> Den onsdagen den 30:e oktober 2013 kl. 11:08:11 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:
> 
> > 
I suddenly realised i mixed code from a plain square system with the generic exponential modulus system.

Here is the code, what it does is encode numbers in an exponential modulus base. So it is basicly a numbersystem of my own you do not need to write out + ^ and exponent because the numbersystem create unique values for every natural number.

Well without the + ^ it is hard to read but so are binary, ternary and hexadecimal. I think the requirment for a numbersystem is that it have a working arithmetic, and mine have.

So here is the working code, to write out exponential modulus number for and exponent.

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

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

> 
> > > 
> 
> > 
> 
> > > >
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >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.
> 
> > 
> 
> > 
> 
> > 
> 
> > Well Tim ***one could argue*** why not do a (i think it is called parser) that react to "loop", "end" and "function". And lazy like me do not have to think about "what is not part of program".
> 
> > 
> 
> > 
> 
> > 
> 
> > I certainly do not like the old bracket style it was a catastrophe, but in honesty the gui editor of python should have what i propose, a parser that indent automaticly at loops, functions and end. I promise you it will save millions of hours of bug searching all over world in a month.
> 
> 
> 
> Instead of having going over indent manually, you just drop in an end it is so simple, no marking no meny indent unindent it is automaticly done. And that was the purpose of python to remove idiocies, like brackets and indents.



More information about the Python-list mailing list