Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Google Treasure solution in python - first time python user, helpwhats wrong

Reply
Thread Tools

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

 
 
x40
Guest
Posts: n/a
 
      05-23-2008
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')
 
Reply With Quote
 
 
 
 
Gabriel Genellina
Guest
Posts: n/a
 
      05-25-2008
En Fri, 23 May 2008 05:40:26 -0300, x40 <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
national treasure s00 burton Computer Support 0 02-08-2005 08:50 AM
Disney The Treasure set Larry Gold DVD Video 2 07-03-2004 03:53 PM
Disney Treasure advise Please Dragon DVD Video 5 02-16-2004 11:41 AM
DVD Verdict reviews: THE TREASURE OF THE SIERRA MADRE and more! DVD Verdict DVD Video 0 10-22-2003 09:04 AM
Treasure of the Sierra Madre Dunf DVD Video 8 10-12-2003 01:40 AM



Advertisments