Difference between revisions of "Python:Accumulators For Searching Tutorial"

From Progzoo
Jump to: navigation, search
(Created page with "{{Accumulator Tutorial}} <shell lang=py>QcQ</shell> ==The biggest population== <question xmlns:htm="http://www.w3.org/1999/xhtml" copyFile="cia.txt"><prog> fh = open("cia.txt"...")
 
 
Line 100: Line 100:
 
</prog><answer>
 
</prog><answer>
 
fh = open("cia.txt","r")
 
fh = open("cia.txt","r")
acc = 0
+
acc = 1000000000000
 
who = ""
 
who = ""
 
for line in fh:
 
for line in fh:
Line 110: Line 110:
 
       gdp = int(f[4])
 
       gdp = int(f[4])
 
       if region == "Middle East":
 
       if region == "Middle East":
         acc = max(acc,pop)
+
         acc = min(acc,pop)
 
         if acc==pop:
 
         if acc==pop:
 
           who=name
 
           who=name

Latest revision as of 17:48, 12 July 2017

The biggest population

What is the population of the largest country (by population).

[Font] [Default] [Show] [Resize] [History] [Profile]

Which country has the biggest population?

What is the name of the largest country (by population).

[Font] [Default] [Show] [Resize] [History] [Profile]

Which middle eastern country has the smallest population?

What is the name of the country in region "Middle East" with the smallest population.

[Font] [Default] [Show] [Resize] [History] [Profile]