Name the Country: Python Challenge


In this challenge, you will use your Python skills to create a quiz where the player has to guess the name of a country when they can only see the first letter of that country.

When a player gives an incorrect guess, the next letter of the correct answer is revealed.

The quiz should have a scoring system that adds to the player score a number of points corresponding to the number of letters still hidden.

The quiz should repeat itself 10 times, each time with a different country. At the end the computer should reveal the total score of the player.

As an extension task, a leader board should be added to store the player’ name and score in a text file (CSV format).

Structure Diagram

Here is the structure diagram (Decomposition diagram) for this project:

The main tasks for this project are as follows:

    Initialise the game

       Initialise a list of at least 20 countries
       Initialise player score to 0

    Quiz Engine

       Randomly pick a country from the list of countries
       Display the clue (e.g. C _ _ _ _ _ )
       Collect the user guess
       Check if the user is correct and if not repeat the process with a new clue.
       If the user is correct, calculate and display their new score
       Repeat the quiz 10 times with 10 different countries

    Game Over / Leaderboard

       Display a “Game Over” message and the total score
       Ask the player to enter their name
       Store the player’s name and score in a leaderboard file
       Display the leader board (Top 10 scores in descending order)

Displaying the Clue

To help you with this project, we have already created a procedure called displayClue() that takes two parameters: word and x and displays the first x letter of a word following with _ characters for each remaining letters of the given word.

The Python code for our function is as follows:

# A subroutine to display the first x letters of a word
# and replace the remaining letters with _
def displayClue(word,x):
   clue = ""
   for i in range (0, len(word)):
      if i<x:
         clue = clue + word[i]
      else:
         clue = clue + "_"
      clue = clue + " "   
   print("Name the country: " + clue.upper())

Python Code

Your task is to complete the code below to recreate this “Name the Country” Quiz:

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 2.6 / 5. Vote count: 10

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!