<jupyter_start><jupyter_text>Initiliaze parameters used through the program<jupyter_code>def init_messages():
    msg_types = collections.defaultdict(bool)
    #msg_types[True] = "Good job! This is the right answer"
    #msg_types[False] = "Too bad! that is not the correct answer"
    msg_types[True] = r"Congrats, {} is the right answer"
    msg_types[False] = r"Sorry, you have {} changes left"
    
    return msg_types
def init_questions():
    questions = [('Who won 13 <NAME> cups?','nadal'), ('How many students do our class have', '14'),
                ('Who sings La vida loca','<NAME>'), ('Question optionnelle','4')]
    return questions
MESSAGES = init_messages()
QUESTIONS = init_questions()<jupyter_output><empty_output><jupyter_text>1. Function to ask a question<jupyter_code>def ask_question(question, num=0):
    '''
    Asks a question to a user, get the answer and return it.
        question: Question displayed to the user
        num : The number of the question.  By default is zero,
    '''
    num_question = str(num) if num > 0 else ''
    user_answer = str(input(f"Question {num_question}: {question}"))
    #print(f"Your answer : {user_answer}")
    return user_answer<jupyter_output><empty_output><jupyter_text>2. Function to compare the user answer with the right answer<jupyter_code>def is_answer_ok(correct_answer, user_answer):
    return correct_answer == user_answer.lower()<jupyter_output><empty_output><jupyter_text>3. Function to display a message to user according to its answer<jupyter_code>def display_message(type_msg:bool, msg_param):
    '''
    Returns the message to be displayed to a user after it gave a response to a question
    Parameters:
    --------------------
        type_msg: 2 values are possible: True or False
        msg_param: A specific value to customize in the message
            when an type_msg = ok , the correct answer should be passed.
            when an type_msg = nok, the number of tries left should be passed.
        
        returns a str message
    '''
    return MESSAGES[type_msg].format(msg_param)
    
def print_intro():
    print("Welcome to our quizz!")
    print("You have 3 lives.\n")<jupyter_output><empty_output><jupyter_text>def print_chances_left(n_tries_done, max_tries):    print (f"Sorry, you have {max_tries - n_tries_done} chance(s) left")<jupyter_code>print_chances_left(2, 3)<jupyter_output><empty_output><jupyter_text>4. Some tests<jupyter_code>def test_answer_ok():
    print('init')
    question, answer = QUESTIONS[0]
    user_answer = ask_question(question)
    print(f'user_answer .... {user_answer}')
    print (MESSAGES[is_answer_ok(answer, user_answer)])
    #display_message(is_ok)
is_ok = is_answer_ok("8", "user_answer")
print(MESSAGES[False].format('888'))
test_answer_ok()<jupyter_output>Who won 13 Roland Garros cups? nadal<jupyter_text>Function to launch a quiz<jupyter_code>def launch_quiz(n_questions = 1, max_tries = 3):
    '''
    Launches a series of questions to the user.  If the user answer wrong to max_tries questions
    then the quiz stops and the user lost the game.
    Parameters:
    ------------
    n_questions: The number of questions the user want to answer
    max_tries: The max attemtps the user.  
    
    '''
    print_intro()
    final_message = "\n Well done! You are the quiz winner"
    questions_count = 0
    n_tries = 0
    for i, (question, answer) in enumerate(QUESTIONS):
        is_ok = False
        
        while not(is_ok) and n_tries<max_tries:
            user_answer = ask_question(question, i+1)
            is_ok = is_answer_ok(answer, user_answer)
            if not(is_ok):
                n_tries +=1
                
                print(MESSAGES[is_ok].format(max_tries - n_tries))
            else:
                print(MESSAGES[is_ok].format(user_answer))
        questions_count += 1
        if not(is_ok):
            final_message = "\n Too bad, you lost the game"
                
        if questions_count >= n_questions or not(is_ok): # if we reached the max questions to be asked
            break
    print(final_message)<jupyter_output><empty_output><jupyter_text>Main> Launch the quiz<jupyter_code>launch_quiz(2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10361958836053939, 'fraction_numerical': 0.007097232079488999, 'mean_word_length': 3.3408624229979464, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '565651', 'license': 'MIT', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1325, 'n_words': 379, 'path': 'projects/01-quiz/launch-quiz.ipynb', 'repo_name': 'pattypooh/pez-jedha', 'size': '4240'}