what can i do to improve my skill after finished python course on codecademy

Dave Angel davea at davea.name
Sun Nov 2 17:07:34 EST 2014


On 11/02/2014 04:03 PM, Seymore4Head wrote:
> On Sun, 02 Nov 2014 19:42:49 +0000, Mark Lawrence
> <breamoreboy at yahoo.co.uk> wrote:
>
>> On 02/11/2014 19:10, Seymore4Head wrote:
>>> On Sun, 2 Nov 2014 12:16:11 -0500, Joel Goldstick
>>> <joel.goldstick at gmail.com> wrote:
>>>
>>>> On Sun, Nov 2, 2014 at 10:08 AM, Peter Otten <__peter__ at web.de> wrote:
>>>>> Huhuai Fan wrote:
>>>>>
>>>>>> Thanks for your help, but i have no idea to find a project that i can
>>>>>> complete,i am now in perplexed for what to do
>>>>>
>>>>> Then write a small text-based brainstorming app!
>>>>>
>>>>> --
>>>>> https://mail.python.org/mailman/listinfo/python-list
>>>>
>>>> If you like math puzzles you can do the euler project stuff
>>>
>>> target=1000
>>> thelist=[]
>>> thesum=0
>>> for x in range (1,target):
>>>       if x%3==0: thelist.append(x)
>>>       if x%5==0 and x%3!=0: thelist.append(x)
>>> for x in thelist: thesum+=x
>>> print(thelist)
>>> print (thesum)
>>>
>>
>> In [1]: help(sum)
>> Help on built-in function sum in module builtins:
>>
>> sum(...)
>>      sum(iterable[, start]) -> value
>>
>>      Return the sum of an iterable of numbers (NOT strings) plus the value
>>      of parameter 'start' (which defaults to 0).  When the iterable is
>>      empty, return start.
>
> BTW I have the answer to question 2, but there is no way I would run
> the code on numbers much more than 100000 and it wants the answer for
> 4,000,000.
>

So that's teaching you that there must be a more elegant approach than 
brute-force.  Sometimes you can use cleverer programming, sometimes you 
need cleverer math.  Sometimes both.

As a trivial example, suppose you're asked to sum the numbers from 1000 
to 10**25

Brute force would take a few millenia, as something like
     ans = sum(range( BIG ) - sum(range(1000))

But just knowing the math lets you simplify it to something like
    ans = (1000 + BIG) * (BIG - 1000) / 2

(give or take a few plus/minus ones)



-- 
DaveA



More information about the Python-list mailing list