Differences

This shows you the differences between two versions of the page.

Link to this comparison view

bird [2008/01/17 08:57]
jtk
bird [2008/01/17 08:57]
Line 1: Line 1:
-//A slight variation of what was given in class.// 
-<​html><​pre>​ 
-import string 
- 
-def main(search):​ 
-    total = 0 
-    c = 0 
-    ​ 
-    infile = open("​birdlist48.csv"​) 
-    infile.readline() 
-    infile.readline() 
- 
-    for line in infile: 
-        # print line 
-        fields = string.split(line,​ ","​) 
-        if fields[0]: 
-            order = string.capwords(fields[0]) 
-        name = fields[6] 
-        if name: 
-            total = total + 1 
-        if name and string.find(string.lower(name),​ search) >= 0: 
-            c = c + 1 
-            genus = fields[4] 
-            species = fields[5] 
-            print "%-30s (%s %s, order %s)" % (name, genus, species, order) 
-    print "%d birds, of which %d match %s" % (total, c, search) 
-    ​ 
-main("​hawk"​) 
- 
-</​pre></​html>​ 
- 
-// The version developed in class... // 
- 
-<​html><​pre>​ 
-import string 
- 
-def main(search):​ 
-    total = 0 
-    c = 0 
-    ​ 
-    infile = open("​birdlist48.csv"​) 
-    infile.readline() 
-    infile.readline() 
- 
-    for line in infile: 
-        # print line 
-        fields = string.split(line,​ ","​) 
-        if fields[0]: 
-            order = string.capwords(fields[0]) 
-        name = fields[6] 
-        if name: 
-            total = total + 1 
-        if name and string.find(string.lower(name),​ search) >= 0: 
-            c = c + 1 
-            genus = fields[4] 
-            species = fields[5] 
-            print "%-30s (%s %s, order %s)" % (name, genus, species, order) 
-    print "%d birds, of which %d match %s" % (total, c, search) 
-    ​ 
-main("​hawk"​) 
-</​pre></​html>​ 
  
 
bird.txt ยท Last modified: 2008/01/17 08:57 (external edit)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki