473,386 Members | 1,726 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,386 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 1415
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.