コード例 #1
0
def population_question(data: list) -> Question:
    question_choice = choice(['largest', 'smallest'])
    question_text = f'Which of these countries has the {question_choice} population?'

    # Create answers.
    answers = []
    for element in data:

        # Create useful data from urls.
        country = get_resource_url(element, 'country')
        population = int(get_resource_url(element, 'population'))

        # Format so it's easy to work with.
        answers.append({'population': population, 'country': country})

    # Sort from largest population to smallest, or reverse.
    answers.sort(key=lambda x: x['population'], reverse=False if question_choice == 'smallest' else True)

    # Creates answer-objects.
    answers = [
        Answer(answer['country'], True if i == 0 else False, f"That is correct! The population of {answer['country']} is around {round(answer['population'] / 1_000_000, 1)} Million.")
        for i, answer in enumerate(answers)
        ]


    shuffle(answers)
    return Question(question_text, answers)
コード例 #2
0
def actor_has_actor_parent_question(data: list) -> Question:
    answers = []
    for i, element in enumerate(data):
        actor = get_resource_url(element, "actorLabel")
        parent_value = get_resource_url(element, "bool")

        if i == 0:
            question_text = f"Did the actor {actor} have a parent who was also an actor?"
            answer_text = f"That is correct"
            answers.append(Answer(parent_value, True, answer_text))

        else:
            answer_text = f"That is incorrect"
            answers.append(Answer(parent_value, False, answer_text))

    shuffle(answers)
    return Question(question_text, answers)
コード例 #3
0
def currency_question(data: list) -> Question:
    answers = []

    for i, element in enumerate(data):
        country = get_resource_url(element, "country")
        currency_code = element["currencyCode"]["value"]
        
        if i == 0:
            question_text = f"What currency code does {country} use?"
            answer_text = f"That is correct {country} has {currency_code} as their currency code."
            answers.append(Answer(currency_code, True, answer_text))
        
        else:
            answer_text = f"That is incorrect, {country} has {currency_code} as their currency code."
            answers.append(Answer(currency_code, False, answer_text))
    
    shuffle(answers)
    return Question(question_text, answers)
コード例 #4
0
def capital_question(data: list) -> Question:

    # Create answers.
    answers = []
    for i, element in enumerate(data):

        # Create useful data from urls.
        country = get_resource_url(element, 'country')
        capital = get_resource_url(element, 'capital')

        # First element is the correct answer.
        if i == 0:
            question_text = f'What is the capital of {country}?'
            answers.append(Answer(capital, True, f'That is correct, the capitol of {country} is {capital}'))
        else:
            answers.append(Answer(capital, False, f'That is incorrect, the capitol of {country} is {capital}'))

    shuffle(answers)
    return Question(question_text, answers)
コード例 #5
0
def island_question(data: list) -> Question:

    answers = []
    for i, element in enumerate(data):

        country = get_resource_url(element, 'country')
        island = get_resource_url(element, 'island')

        if i == 0:
            question_text = f'In what country is the island {island} located in?'
            answer_text = f'That is correct, the island {island} is located in {country}.'
            answers.append(Answer(country, True, answer_text))

        else:
            answer_text = f'That is incorrect, the island {island} is located in {country}.'
            answers.append(Answer(country, False, answer_text))

    shuffle(answers)
    return Question(question_text, answers)
コード例 #6
0
def land_locked_question(data: list) -> Question:
    answers = []

    for i, element in enumerate(data):
        
        country = get_resource_url(element, "countryLabel")
        locked_value = get_resource_url(element, "locked")

        if i == 0:
            question_text = f'Is {country} landlocked?'
            answer_text = f'That is correct'
            answers.append(Answer(locked_value, True, answer_text))

        else:
            answer_text = f'That is incorrect'
            answers.append(Answer(locked_value, False, answer_text))

    shuffle(answers)
    return Question(question_text, answers)
コード例 #7
0
def olympics_question(data: list) -> Question:
    
    answers = []
    for i, element in enumerate(data):

        country = get_resource_url(element, 'country')
        olympic = get_resource_url(element, 'olympic')

        if i == 0:
            question_text = f'What country hosted the {olympic} olympics?'
            answer_text = f'That is correct, {country} hosted the {olympic} olympics.'
            answers.append(Answer(country, True, answer_text))

        else:
            answer_text = f'That is incorrect, {country} hosted the {olympic} olympics.'
            answers.append(Answer(country, False, answer_text))

    shuffle(answers)
    return Question(question_text, answers)
コード例 #8
0
def country_neighbors_question(data: list) -> Question:
    
    answers = []
    for i, element in enumerate(data):
        
        start_country = get_resource_url(element, "startLabel")
        middle_country = get_resource_url(element, "middleLabel")
        end_country = get_resource_url(element, "endLabel")

        if i == 0:
            question_text = f"What common neighbour does {start_country} and {end_country} have?"
            answers_text = f"That is correct, {middle_country} connects {start_country} and {end_country}."
            answers.append(Answer(middle_country, True, answers_text))

        else:
            answer_text = f"That is incorrect, {middle_country} is neighbours with {start_country} and {end_country}."
            answers.append(Answer(middle_country, False, answer_text))
    
    shuffle(answers)
    return Question(question_text, answers)
コード例 #9
0
def largest_city_question(data: list) -> Question:
    question_choice = choice(['largest', 'smallest'])  
    question_text = f'Which of these cities has the {question_choice} population?' 

    answers = []
    for element in data:  
        city = get_resource_url(element, "cityLabel")
        population = int(get_resource_url(element, 'population'))
        
        answers.append({'population': population, 'city': city})

    answers.sort(key=lambda x: x['population'], reverse=False if question_choice == 'smallest' else True)

    answers = [
        Answer(answer['city'], True if i == 0 else False, f"That is correct! The population of {answer['city']} is around {round(answer['population'] / 1_000_000, 1)} Million.")
        for i, answer in enumerate(answers)
    ]


    shuffle(answers)
    return Question(question_text, answers)
コード例 #10
0
def actors_question(data: list) -> Question:
    question_data = []
    for element in data:
        actors = get_resource_url(element, "actors").split(",")
        movie = get_resource_url(element, "movieLabel")
        question_data.append([movie, set(actors)])

    # Remove actors from other movies to make sure we dont get multiple correct alternatives
    # Removes all actors which were present in both the first movie (we base our question on) and in each other movie
    for i in range(len(question_data) - 1):
        question_data[0][1] - question_data[i + 1][1]

    # Converts back to list
    for i in range(len(question_data)):
        question_data[i][1] = list(question_data[i][1])

    answers = []
    for i, element in enumerate(question_data):
        movie = element[0]
        actor = element[1]

        if i == 0:
            two_random_actors = sample(actor, 2)
            question_text = f"In which movie did {two_random_actors[0]} and {two_random_actors[1]} play together?"
            answers.append(
                Answer(
                    movie, True,
                    f"That is correct, {two_random_actors[0]} and {two_random_actors[1]} played together in {movie}"
                ))

        else:
            answers.append(
                Answer(
                    movie, False,
                    f"That is incorrent, {two_random_actors[0]} and {two_random_actors[1]} played together in {movie}"
                ))

    shuffle(answers)
    return Question(question_text, answers)
コード例 #11
0
def academy_awards_person_question(data: list) -> Question:
    answers = []
    for i, element in enumerate(data):
        award_count = get_resource_url(element, "count")
        person = get_resource_url(element, "actorLabel")

        if i == 0:
            question_text = f"How many academy awards has {person} won?"
            answers.append(
                Answer(
                    award_count, True,
                    f"That is correct, {person} has won {award_count} academy awards."
                ))

        else:
            answers.append(
                Answer(
                    award_count, False,
                    f"That is incorrect, {person} has won {award_count} academy awards."
                ))

    shuffle(answers)
    return Question(question_text, answers)
コード例 #12
0
def movie_length_question(data: list) -> Question:
    question_choice = choice(["longest", "shortest"])
    question_text = f"Which of these movies has the {question_choice} runtime?"

    answers = []
    for element in data:
        movie = get_resource_url(element, "movieLabel")
        runtime = round(float(get_resource_url(element, "lengthLabel")))

        answers.append({"movie": movie, "runtime": runtime})

    answers.sort(key=lambda x: x['runtime'],
                 reverse=False if question_choice == 'shortest' else True)

    answers = [
        Answer(
            answer['movie'], True if i == 0 else False,
            f"That is correct! The runtime of {answer['movie']} is around {answer['runtime'] / 60, 2} Hours."
        ) for i, answer in enumerate(answers)
    ]

    shuffle(answers)
    return Question(question_text, answers)
コード例 #13
0
def release_year_question(data: list) -> Question:
    answers = []
    for i, element in enumerate(data):
        year = get_resource_url(element, "year")
        movie = get_resource_url(element, "movieLabel")

        if i == 0:
            question_text = f"When was the movie {movie} released?"
            answers.append(
                Answer(
                    year, True,
                    f"That is correct, the movie {movie} was realeased in {year}"
                ))

        else:
            answers.append(
                Answer(
                    year, False,
                    f"That is incorrect, the movie {movie} was realeased in {year}"
                ))

    shuffle(answers)
    return Question(question_text, answers)
コード例 #14
0
def director_question(data: list) -> Question:
    answers = []
    for i, element in enumerate(data):
        director = get_resource_url(element, "directorLabel")
        movie = get_resource_url(element, "movieLabel")

        if i == 0:
            question_text = f"Who directed {movie}?"
            answers.append(
                Answer(
                    director, True,
                    f"That is correct, the director of {movie} was {director}."
                ))

        else:
            answers.append(
                Answer(
                    director, False,
                    f"That is incorrect, the director of {movie} was {director}."
                ))

    shuffle(answers)
    return Question(question_text, answers)