Question
Using Python software create code to accomplish the following: (Please show actual coding) Create your own quiz with five or more questions. You can ask
Using Python software create code to accomplish the following: (Please show actual coding)
Create your own quiz with five or more questions. You can ask questions that require:
a number as an answer (e.g., What is 1+1?)
text (e.g. What is Harry Potter's last name?)
a selection (Which of these choices are correct? A, B, or C?)
If you have the user enter non-numeric answers, think and cover the different ways a user could enter a correct answer. For example, if the answer is a, would A also be acceptable? SeeSection 3.6 for a reminder on how to do this.
Let the user know if he or she gets the question correct. Print a message depending on the user's answer.
You need to keep track of how many questions they get correct.
At the end of the program print the percentage of questions the user gets right.
Keep the following in mind when creating the program:
Variable names should start with a lower case letter. Upper case letters work, but it is not considered proper. (Right, you didn't realize that programming was going to be like English Tea Time, did you?)
To create a running total of the number correct, create a variable to store this score. Set it to zero. With an if statement, add one to the variable each time the user gets a correct answer. (How do you know if they got it correct? Remember that if you are printing out correct then you have already done that part. Just add a line there to add one to the number correct.) If you don't remember how to add one to a variable, go back and review Section 1.5.
Treat true/false questions like multiple choice questions, just compare to True or False. Don't try to do if a: we'll implement if statements like that later on in the class, but this isn't the place.
Calculate the percentage by using a formula at the end of the game. Don't just add 20% for each question the user gets correct. If you add 20% each time, then you have to change the program 5 places if you add a 6th question. With a formula, you only need 1 change.
To print a blank line so that all the questions don't run into each other, use the following code:
print() |
Remember the program can print multiple items on one line. This can be useful when printing the user's score at the end.
print("The value in x is", x) |
Separate out your code by using blank lines to group sections together. For example, put a blank line between the code for each question.
Sometimes it makes sense to re-use variables. Rather than having a different variable to hold the user's answer for each question, you could reuse the same one.
Use descriptive variable names. x is a terrible variable name. Instead use something like number_correct.
Don't make super-long lines. Chances are you don't need to use at all. Just use multiple print statements.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started