473,289 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

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

x40
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')
Jun 27 '08 #1
1 1408
En Fri, 23 May 2008 05:40:26 -0300, x40 <ma************@gmail.comescribió:
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

Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jason willows | last post by:
There have been many many many many discussions about obfuscating python. To my dismay, most who answer are those who frequently post, and they say things such as: 1) what's the point, in theory...
23
by: Simon Wittber | last post by:
For the first time, I have been bitten by Python. The below code produces the results: False True when I initially expected the results: False False It took me a while to work out that...
36
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but...
137
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very...
21
by: Jay Levitt | last post by:
I'm just starting to play around with CSS and MovableType. My home page (http://www.jay.fm) now validates on both the CSS and the XHTML. However, the Google cached version shows the wrong font in...
25
by: Tor Erik Sønvisen | last post by:
Hi I need to browse the socket-module source-code. I believe it's contained in the file socketmodule.c, but I can't locate this file... Where should I look? regards tores
17
by: =?Utf-8?B?Y2F0aGFyaW51cyB2YW4gZGVyIHdlcmY=?= | last post by:
Hello, I have build a website with approximately 30 html-pages. When I search this website in Google, I see the index.html or home.html on this website, but also other html-pages on this...
24
by: Joe Salmeri | last post by:
I just upgraded from Python 2.4.2 to Python 2.5.1 and have found some unexpected behavior that appears to be a bug in the os.stat module. My OS is Windows XP SP2 + all updates. I have several...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.