Feb-12-2021, 12:45 PM
Hi, so i'm creating a basic quiz which incorporates lists, functions, dictionaries and interactive loops.
The quiz is on Capital Cities. The user is shown a Country and then a Capital City which is chosen at random. The user is asked if it's the right or wrong Capital City. If they are right, they get a message 'Correct, the capital city of .... is ....', if they are wrong they get a message 'Incorrect, the capital city of .... is ....
In terms of where I am at, the program output gives the right capital city everytime and it does not randomise value in otherwords the capital city.
What am I struggling with?
1/ I'm struggling to randomise the dictionary value so that the program randomly chooses whether to give the right or wrong capital city
2/ Once I get part 1 working. How do I then write the 'if' part of the program. So basically: If the user is correct, say correct the capital city of .... is ..... and if they guess incorrect say incorrect, the capital city of .... is ....
In terms of what I have achieved so far, this is what I have got:
The quiz is on Capital Cities. The user is shown a Country and then a Capital City which is chosen at random. The user is asked if it's the right or wrong Capital City. If they are right, they get a message 'Correct, the capital city of .... is ....', if they are wrong they get a message 'Incorrect, the capital city of .... is ....
In terms of where I am at, the program output gives the right capital city everytime and it does not randomise value in otherwords the capital city.
What am I struggling with?
1/ I'm struggling to randomise the dictionary value so that the program randomly chooses whether to give the right or wrong capital city
2/ Once I get part 1 working. How do I then write the 'if' part of the program. So basically: If the user is correct, say correct the capital city of .... is ..... and if they guess incorrect say incorrect, the capital city of .... is ....
In terms of what I have achieved so far, this is what I have got:
from random import * def show_capital_city(): random_capital = choice(list(capital_cities)) print('Define: ', (random_capital)) print(capital_cities[random_capital]) input('Is this the right capital city? Enter Y or N') capital_cities = {'Australia': 'Canberra', 'Brazil': 'Brasilia', 'Cuba': 'Havana', 'France': 'Paris', 'Germany': 'Berlin', 'United States': 'Washington D.C'} # s to start or q to quit if use enters something else ask again exit = False while not exit: user_input = input('Enter s to start and q to quit: ') if user_input == 'q': exit = True elif user_input == 's': show_capital_city() else: print('You need to enter either q or s.')Any help, guidance, tips would be really appreciated!