Python 8.2 : Exercise : Coding a questionnaire
We will continue with our learning and here we will do an exercise, the purpose of the exercise is to make ... a questionnaire. The questionnaire must have 3 questions you will ask the user Question 1 for example here put question one you ask: What is the capital of France? And Question 2 here what is the capital of Italy? and question 3 you will search, so the purpose of the exercise is displayed on the screen the questions the answers and to ask the question to the user by asking the answer so we will put here your answer like this and if, it puts for example the answer a it is bad answer, if it puts the answer c it is... good answer. Concerning the question one you are going to do the same for the question 2 so we come back in a few minutes for the correction concerning the correction we are going to begin by returning to the screen the question asked by doing a print double parenthesis you are going to copy this I am going to paste I made a second print And I copy this answer third print I copy this fourth print I copy this fifth print I copy this now have to retrieve the answer by doing answer equals input and I copy this your answer I paste Now we check if answer equals c colon print right answer else print wrong answer I'm going to run my code you see that it displays the right answer I'm going to put a wrong answer I'm going to raise I'm going to put b wrong answer I put c right answer And I was done the same thing for the second question I copied this I will paste Here I will put you more question 2 and I will put the capital of Italy here a I am going to put Rome b I am going to put Venice c I am going to put Florence and d I am going to put Pisa Here and if we are going to change the answer it is a I raise I am going to put c Good answer a Good answer that was the very simple method for this code and it works but the problem with code is that if for example we have 100 questions and we have to rewrite the code for 100 questions, but imagine if we want to modify the questions each time it becomes difficult for us, that's when we use the functions, which will help us to have a simple dynamic code that we can modify at any time and it works it totally works and if we want to add some elements like the core, or the number of questions ... you had, the number of questions you had the number of right answers the number ... of wrong answers regarding the refactoring.