IA Dictionary Question

This is place to ask questions, get clarifications, and ask for help about your internal assessment.
Forum rules
Please be careful about sharing personal information. Never use any identifiable information.
Post Reply
zosiak
New User
Posts: 2
Joined: 22 May 2018, 08:35

IA Dictionary Question

Post by zosiak » 20 Dec 2018, 21:56

Hi Mr. Mackenty,

I have a question about my code. On lines 3-103, I have a dictionary of 100 items. On line 139, I generate a number between 0 and 99. On line 140, I attempted to get the whole "key" part of whatever dictionary item I want. So, if line 139 generates the number 17, I want line 140 to get the key value of the 17th thing in the dictionary.

I am not sure how to do this. Would it be better to use a 2d array instead of a dictionary? If there's no other way then I will convert it to a list, however this will take a while so it'd be nice if this was possible to do in a dictionary.

Also I'm not really sure how to make this code have Python formatting and I asked some people but I'm still not sure. Could you explain this to me apart from answer my question about code?

Have a great rest of the break and thank you very much in advance!

Code: Select all


import random

questions = {
"What is the capital of Poland	?	|––>   	"	:	"	Warsaw	",
"What is the capital of Ukraine	?	|––>   	"	:	"	Kiev	",
"What is the capital of Finland	?	|––>   	"	:	"	Helsinki	",
"What is the capital of Norway	?	|––>   	"	:	"	Oslo	",
"What is the capital of Sweden	?	|––>   	"	:	"	Stockholm	",
"What is the capital of Italy	?	|––>   	"	:	"	Rome	",
"What is the capital of Luxembourg	?	|––>   	"	:	"	Luxembourg	",
"What is the capital of Brazil	?	|––>   	"	:	"	Brasilia	",
"What is the capital of Turkey	?	|––>   	"	:	"	Ankara	",
"What is the capital of Thailand	?	|––>   	"	:	"	Bangkok	",
"What is the capital of South Korea	?	|––>   	"	:	"	Seoul	",
"What is the capital of Mexico	?	|––>   	"	:	"	Mexico City	",
"What is the capital of Germany	?	|––>   	"	:	"	Berlin	",
"What is the capital of Czech Republic	?	|––>   	"	:	"	Prague	",
"What is the capital of Hungary	?	|––>   	"	:	"	Budepest	",
"What is the capital of Spain	?	|––>   	"	:	"	Madrid	",
"What is the capital of Portugal	?	|––>   	"	:	"	Lisbon	",
"What is the capital of Russia	?	|––>   	"	:	"	Moscow	",
"What is the word for 'thank you' in French	?	|––>   	"	:	"	Merci	",
"What is the word for 'thank you' in Italian	?	|––>   	"	:	"	Grazie	",
"What is the word for 'thank you' in Arabic	?	|––>   	"	:	"	Shokran	",
"What is the word for 'thank you' in Polish (w/o special characters)	?	|––>   	"	:	"	Dziekuje	",
"What is the word for 'thank you' in Spanish	?	|––>   	"	:	"	Gracias	",
"What is the word for 'thank you' in Japanese	?	|––>   	"	:	"	Arigato	",
"What is the word for 'thank you' in Czech?	?	|––>   	"	:	"	Diakuju	",
"What is the last name of the current Polish president	?	|––>   	"	:	"	Duda	",
"What is the last name of the current US president	?	|––>   	"	:	"	Drumpf	",
"What is the last name of the previous US president	?	|––>   	"	:	"	Obama	",
"What is the last name of the composer of The Four Seasons	?	|––>   	"	:	"	Vivaldi	",
"What is the last name of the most well-known Polish sooccer player	?	|––>   	"	:	"	Lewandowski	",
"What is the last name of the singer of Billie Jean and Thriller	?	|––>   	"	:	"	Jackson	",
"What is the last name of the singer of Back to Black and Rehab	?	|––>   	"	:	"	Winehouse	",
"What is the last name of the fastest human in the world	?	|––>   	"	:	"	Bolt	",
"What is the last name of the singer of All I Want For Christmas is You	?	|––>   	"	:	"	Carey	",
"What is the last name of the singer of Imagine and Yesterday	?	|––>   	"	:	"	Lennon	",
"What is the name of Batman's city	?	|––>   	"	:	"	Gotham	",
"What is the last name of the emperor that burned Rome	?	|––>   	"	:	"	Nero	",
"Traditionally, how many wonders of the world are there? (answer in word form)	?	|––>   	"	:	"	Seven	",
"What is the first planet from the sun	?	|––>   	"	:	"	Mercury	",
"What is the second planet from the sun	?	|––>   	"	:	"	Venus	",
"What is the third planet from the sun	?	|––>   	"	:	"	Earth	",
"What is the fourth planet from the sun	?	|––>   	"	:	"	Mars	",
"What is the fifth planet from the sun	?	|––>   	"	:	"	Jupiter	",
"What is the sixth planet from the sun	?	|––>   	"	:	"	Saturn	",
"What is the seventh planet from the sun	?	|––>   	"	:	"	Uranus	",
"What is the eighth planet from the sun	?	|––>   	"	:	"	Neptune 	",
"Is Pluto a planet?	(yes/no)	?	|––>   	"	:	"	no	",
"To which European capital city	do 'all roads lead'	?	|––>   	"	:	"	Rome	",
"What is the tallest mammal	?	|––>   	"	:	"	Giraffe	",
"The world's highest mountain 	is Mount…..	?	|––>   	"	:	"	Everest	",
"What is the name of the fairy in Peter Pan	?	|––>   	"	:	"	Tinkerbell	",
"What is the name of the hunchback of Notre Dame	?	|––>   	"	:	"	Quasimodo	",
"On the flag of Japan, what color is the circle?	?	|––>   	"	:	"	red	",
"On the flag of Poland, what color is on top	?	|––>   	"	:	"	white	",
"On the flag of Ukraine, what color is on top	?	|––>   	"	:	"	blue	",
"On the flag of Finland, what color is the cross	?	|––>   	"	:	"	blue	",
"On the flag of China, what is the dominating color	?	|––>   	"	:	"	red	",
"On the flag of Vietnam, what color is the star	?	|––>   	"	:	"	yellow	",
"On the flag of South Korea, what color is in the background	?	|––>   	"	:	"	white	",
"On the flag of the US, how many stripes are there (answer in word form)	?	|––>   	"	:	"	thirteen	",
"On the flag of the US, how many stars are there (answer in word form)	?	|––>   	"	:	"	fifty	",
"In Greek mythology, what is the name of the king who turned all that he touched into gold	?	|––>   	"	:	"	midas	",
"What is the last name of the author of Harry Potter	?	|––>   	"	:	"	Rowling	",
"What is the last name of the author of Divergent	?	|––>   	"	:	"	Ruth	",
"What is the last name of the author of The Godfather	?	|––>   	"	:	"	King	",
"What is the last name of the author of the Lord Of The Rings	?	|––>   	"	:	"	Tolkien	",
"What is the chemical symbol for oxygen	?	|––>   	"	:	"	O	",
"What is the chemical symbol for hydrogen	?	|––>   	"	:	"	H	",
"What is the chemical symbol for sodium	?	|––>   	"	:	"	Na	",
"What is the chemical symbol for helium	?	|––>   	"	:	"	He	",
"How many sides does an	octagon have (answer in word form)	?	|––>   	"	:	"	Eight	",
"How many sides does a hexagon have (answer in word form)	?	|––>   	"	:	"	Six	",
"How many sides does a pentagon have (answer in word form)	?	|––>   	"	:	"	Five	",
"How many sides does a decagon have (answer in word form)	?	|––>   	"	:	"	Ten	",
"How many years in a decade (answer in word form)	?	|––>   	"	:	"	Ten	",
"How many years in a century (answer in word form)	?	|––>   	"	:	"	Hundred	",
"How many years in a millenium (answer in word form)	?	|––>   	"	:	"	Thousand	",
"What does the F stand for in FBI	?	|––>   	"	:	"	Federal	",
"What does the A stand for in CIA	?	|––>   	"	:	"	Agency	",
"What is the aloha state ? |––>    "	:	"	Hawaii	",
"In what country can one find the Eiffel tower	?	|––>   	"	:	"	France	",
"In what country can one find the Colloseum	?	|––>   	"	:	"	Italy	",
"In what country can one find the Big Ben	?	|––>   	"	:	"	England	",
"In what country can one find the Taj Mahal	?	|––>   	"	:	"	Indi	",
"Which country is the biggest	?	|––>   	"	:	"	Russia	",
"Which country is the most populated	?	|––>   	"	:	"	China	",
"Which continent is the biggest	?	|––>   	"	:	"	Asia	",
"Which continent is the smallest	?	|––>   	"	:	"	Europe	",
"Which continent is the most populated	?	|––>   	"	:	"	Asia	",
"With how many countries does Poland border (answer in word form)	?	|––>   	"	:	"	Seven	",
"What electronics and media company	is named after a fruit	?	|––>   	"	:	"	Apple	",
"What is the last name of the richest human on Earth	?	|––>   	"	:	"	Gates	",
"Which country uses	S$ as their currency	?	|––>   	"	:	"	Singapore	",
"Is Greece part of the European Union (yes/no)	?	|––>   	"	:	"	Yes	",
"What is the currency in Germany	?	|––>   	"	:	"	Euro	",
"What is the last name of the founder of Facebook	?	|––>   	"	:	"	Zuckenberg	",
"In which state is the Grand Canyon	?	|––>   	"	:	"	Arizona	",
"What is the deadliest snake in the world	?	|––>   	"	:	"	Black Mamba	",
"Is the Great Wall of China	really visible from the moon? (yes/no)	?	|––>   	"	:	"	No	",
"What substance is 	used in thermometers?	|––>   	"	:	"	Mercury	"
}

game = "false"
start = input("Do you want to start game? answer y or n --> ")
if start == "n":
    print ("Goodbye.")
else:
    game = True
 
players = {}
print ("the current players are" + str(players))
 
#ask for amt of players, create dict of players
amount_of_players = input("How many players would you like? (1-4)")
while len(players) < int(amount_of_players):
    new_player_name = ("player" + str(len(players)+1))
    players[new_player_name] = 0
 
#printing the scores
print ("here are the current scores:")
for key,val in players.items():
    print (key, "=>", str(val))
 
#asking for amount of rounds
turns = input("how many questions would you like each player to answer? -->")
amount_of_questions = int(turns) * int(amount_of_players)
print ("Okay. You will play the game for " + str(turns) + " rounds. This means that the game will generate " + str(amount_of_questions) + " questions in total.")

#setting up starting stats
current_turns = 0
question_numbers = list(range(99))
current_player = 0

#actual game
while int(current_turns) < int(turns):
	number_of_question_to_ask = random.randint(0,99)
	current_question = questions.keys()[(to_ask)]

1 x

Post Reply