Zoo tutorials: [ SQL | Linux | XML ]
ProgZoo: [ Java | C# | VB | C++ | Perl ]
Log in

A Gentle Introduction to
Programming

Tutorial: Iterating.

 
to iterate:
To go through every value in a list, or every number in a sequence.

You will need the file world.dat to answer these questions offline.

1. OPEC.


Big

The countries of OPEC in 2005 are Algeria, Libya, Nigeria, Iran, Iraq, Kuwait, Qatar, Saudi Arabia, United Arab Emerates, Venezuela and Indonesia.

For each of the countries of OPEC, print the name and the GDP.

2. OPEC and the Middle East.


Big

We can use an if statement to ensure that only some countries are printed. Do not change the opec list for this question.

For each of the countries of OPEC, print the name and the GDP - only for those OPEC members in the Middle East.

How to filter
Testing the region

3. OPEC printing details.


Big

For each of the countries of OPEC, print the name, the region, the per capita GDP and the GDP in billions.

You may use the following format string to print the details:

"%-21s%-15s%6d%5d\n"

Use 1000000000L for 1 billion (the L means long)

The per capita GDP is the GDP divided by the population.

4. Iterating over the world.


Big

We can iterate over the structure world.values() if we want to process every single country.

Print the name and area of every country in South America.

You may use the following format string to print the details:

"%-21s%9d\n"

How to filter
Testing the region