# Monopoly Quiz

For this challenge you will create a quiz based on the game of Monopoly.

The computer will randomly display a street name from the list of streets used in the game and the user will have to guess the colour used in the game for the selected street.

The user will score one point per correct answer and will be asked to guess the colour of ten different streets, one at a time. At the end the user will be given their score out of ten.

To get you started with this challenge we have created three text files to cater for different audiences:

To complete this challenge you will need to read more about how to read through a CSV file.

#### Complete the Code

We have started the code for you but you will need to complete it to meet all the requirements of this game.

Add a menu option at the beginning to ask the user if they want to play with the UK, US or French monopoly.

Ask the user to enter their name and store their name and final score in a leaderboard text file. See leaderboard challenge.
[pms-restrict display_to=”not_logged_in” message=” “]

#### Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
[/pms-restrict] [pms-restrict subscription_plans=”14217″ message=” “]

#### Solution...

You are viewing this solution as part of your full membership subscription!

Python Code

#### Python Code

```#Monopoly Quiz
import random

def quiz(file):
#Extract all the data from the text file
file = open(file,"r")
file.close

score = 0
#Repeat 10 times
for round in range(1,11):
print("Round " + str(round) + ":")
#Select a random line from the file
randomLine = random.choice(lines)
#Split the two pieces of data, streetname and colour using the ; as separator
data = randomLine.split(";")
streetName = data[0]
colour = data[1].lower()

userGuess=input("What colour is " + streetName + "?").lower()

#Complete the code here to check if the user guess is correct.
if userGuess==colour:
score+=1
print("Correct")
else:
print("Incorrect")

print("Game Over")
print("Final Score: " + str(score) + "ouf of 10")
file.write(username + ";" + str(score) + ";")
file.close()

#Main Program Starts Here
print("\$-\$-\$-\$-\$-\$-\$-\$-\$-\$-\$")
print("\$                   \$")
print("\$   Monopoly Quiz   \$")
print("\$                   \$")
print("\$-\$-\$-\$-\$-\$-\$-\$-\$-\$-\$")
print("")

option=""
while option not in ["UK","US","French"]:
option = input("Would like to play with a UK, US or French monopoly?")

if option=="UK":
quiz("UK-monopoly.txt")
elif option=="US":
quiz("US-monopoly.txt")
elif option=="French":
quiz("French-monopoly.txt")
```
[/pms-restrict]

Did you like this challenge?

Click on a star to rate it!

Average rating 4.9 / 5. Vote count: 7

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

As you found this challenge interesting...