Google Treasure solution in python - first time python user, helpwhats wrong

Discussion in 'Python' started by x40, May 23, 2008.

  1. x40

    x40 Guest

    I try to learn python thru solving some interisting problem, found
    google trasure hunt,
    write first program ( but cant find whats wrong).

    # Unzip the archive, then process the resulting files to obtain a
    numeric result. You'll be taking the sum of lines from files matching
    a certain description, and multiplying those sums together to obtain a
    final result. Note that files have many different extensions, like
    '.pdf' and '.js', but all are plain text files containing a small
    number of lines of text.
    #
    #Sum of line 5 for all files with path or name containing abc and
    ending in .js
    #Sum of line 5 for all files with path or name containing HIJ and
    ending in .js
    #Hint: If the requested line does not exist, do not increment the sum.
    #
    #Multiply all the above sums together and enter the product below.
    #(Note: Answer must be an exact, decimal representation of the
    number.)

    import fnmatch
    import os

    def zbrojipl(pattern):
    rootPath = ''
    sum1=0
    for root, dirs, files in os.walk(rootPath):
    for filename in files:
    path=os.path.join(root, filename)
    if fnmatch.fnmatch(path, pattern):
    #print path
    f=open(path)
    redovi=f.readlines()
    #print len(redovi),redovi
    if len(redovi)>=5:
    #print redovi[4] # index od 0 kao C
    sum1=sum1+int(redovi[4])
    return sum1

    print zbrojipl('*[abc]*.js')*zbrojipl('*[HIJ]*.js')
     
    x40, May 23, 2008
    #1
    1. Advertising

  2. Re: Google Treasure solution in python - first time python user,help whats wrong

    En Fri, 23 May 2008 05:40:26 -0300, x40 <> escribió:

    > I try to learn python thru solving some interisting problem, found
    > google trasure hunt,
    > write first program ( but cant find whats wrong).


    And what happens? You don't get the expected result? The program aborts with an exception? Or what?

    --
    Gabriel Genellina
     
    Gabriel Genellina, May 25, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Treasure Trooper

    , Jul 4, 2006, in forum: Java
    Replies:
    0
    Views:
    349
  2. Treasure Trooper

    , Jul 4, 2006, in forum: Python
    Replies:
    0
    Views:
    328
  3. Treasure Trooper

    , Jul 4, 2006, in forum: C Programming
    Replies:
    0
    Views:
    265
  4. Treasure Trooper

    , Jul 4, 2006, in forum: C++
    Replies:
    0
    Views:
    300
  5. Treasure Trooper

    , Jul 4, 2006, in forum: Perl Misc
    Replies:
    0
    Views:
    112
Loading...

Share This Page