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

Ned Batchelder ned at nedbatchelder.com
Wed Oct 30 08:51:25 EDT 2013


On 10/30/13 6:13 AM, jonas.thornvall at gmail.com wrote:
> Den onsdagen den 30:e oktober 2013 kl. 11:00:30 UTC+1 skrev Mark Lawrence:
>> On 30/10/2013 09:52, jonas.thornvall at gmail.com wrote:
>>
>>
>>
>> Please stop sending us double spaced crap.
>>
>>
>>
>> -- 
>>
>> Python is the second best programming language in the world.
>>
>> But the best has yet to be invented.  Christian Tismer
>>
>>
>>
>> Mark Lawrence
> I am not sure what you want.
> You want me to remove the empty line in function? I do it for it is easier to read for me.

Jonas, he's talking about the quoted content that Google Groups includes 
in your messages.  Some people find this extremely aggravating.

As for your code, you should actually give it much more space:

#!/usr/bin/env python
import math

# Function definition is here
def sq(number):
       square = 1
       factor = 2
       multip = exponent * exponent # not sure why exponent is accessed globally..
       print(x, "= ", end="")

       while number >= multip:
          while square <= number:
             factor += 1
             square = factor * factor
          factor -= 1	
          print(factor, "^", exponent, "+", sep="", end="")
          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)


--Ned.





More information about the Python-list mailing list