# Help!

#1

import random
def loop():
score = 0
ques = input('Would you like to pick a capital and give the country to that capital? If you say no, the computer will generate random capitals and quiz you. yes or no? (PUT YES OR NO IN DOUBLE QUOTES EX: "yes"')
if ques == "yes":
for x in range(1, 10):
quest = input("Pick a capital: ")
if quest in capital:
answe = input("What is the country to this capital?")
if answe in country:
if country.index(answe) == capital.index(quest):
print("You are correct")
score += 1
else:
print("You are wrong")
else:
else:
print("You have recived", score, "point(s)")
elif ques == "no":
for i in range(1, 10):
r = random.randint(0, 246)
ans = country[r]
cap = capital[r]
r1 = random.randint(0, 246)
wrong = country[r1]
r2 = random.randint(0, 246)
wrong1 = country[r2]
r3 = random.randint(0, 246)
wrong2 = country[r3]
print ("What is the country to the capital,", cap)
res = [wrong, ans, wrong1, wrong2]
res.sort()
print (res)
user = input("Enter the answer here (use caps): ")
if user == ans:
print ("congratulations! You're right!! You get a point!!!")
score += 1
elif user not in res:
print (
"The response you have entered is not identified as a response. Please check"
" capitalization and spelling")
error(wrong, ans, wrong1, wrong2, score)
else:
print ("You're as dumb as a bag of poop! :)")
print("You have recived", score, "point(s)")
def error(wrong, ans, wrong1, wrong2, score):
res = [wrong, ans, wrong1, wrong2]
print (res)
user = input("Enter the answer here (use caps): ")
if user == ans:
print ("congratulations! You're right!! You get a point!!!")
score += 1
elif user not in res:
print (
"The response you have entered is not identified as a response. Please check capitalization and spelling")
else:
print ("You're as dumb as a bag of poop! :)")
def isCorrect(user, ans, res):
if user in res:
return true
else:
return false
loop()

This is my code and for some reason I'm getting an error when I run it this is what happens:

('What is the country to the capital,', 'San Salvador')

Traceback (most recent call last):
File "C:\Users\angel\Documents\code\countriescapitals.py", line 75, in
loop()
File "C:\Users\angel\Documents\code\countriescapitals.py", line 40, in loop
user = input("Enter the answer here (use caps): ")
File "", line 1
^
SyntaxError: unexpected EOF while parsing

#2

I would suggest you rewrite this so that it is a dict or a list in a list,

Example

``````countries_captials = {"United Arab Emirates": "Abu Dhabi", "Nigeria": "Abuja"}

# OR

countries_captials = [["United Arab Emirates", "Abu Dhabi"], ["Nigeria", "Abuja"]``````

Then you would do the following to match,

Code:

``````country = "United Arab Emirates"
ask = raw_input("What is the capital of %s: \n" % country).lower()
print("Point")

# OR
from random import randint

country = countries_captials[0, randint(len(countries_captials)) - 1]
ask = raw_input("What is the capital of %s?: \n" % country[0])
print("Point")``````

I would directly associate the data to one another so that you can avoid some complex checking code, if you do with the list of lists you have to search through the whole list each time you want to find a specific instance, while you can access the dict with the country or city depending on hwo you implement it.

I would suggest going with the dict for this because it would work better.

If you want to join both your lists programmatically then do this,

``````hold = dict()
for index, country in enumerate(country):
# City must be in the same order and have the same number of entries
hold[country] = city[index]
# This will save to current directory
with open("countries_cities.txt", "w+") as file:
file.write(hold)``````

Then if you want to load that file.

``````hold = dict()
with open("countries_cities.txt", "r") as file:
file.seek(0)