Question

In: Computer Science

Please make the following modifications to the following code: For each question, instead of keeping score,...

Please make the following modifications to the following code:

  • For each question, instead of keeping score, continue asking the same question until the user guesses the correct question or types "skip" (allow both upper and lower case).
  • If the user guesses correctly, issue a "correct" message,
  • If the user guesses incorrectly, issue a "sorry, try again" message
  • If the user types "skip", print the correct answer and continue to the next question.
  • When all questions have been asked/answered/skipped, ask the user if they would like to play again. If so, start the quiz over again from the beginning. Otherwise, print out a "Thank you for playing" type of message
# A simple program that gives the user a quiz and gives them a score after
#By Abi Santo
#9/27/20
def main():
    print("This Program gives you a quiz and a score after you are done with the quiz")
    quiz_set = [{
        "type" : "single_answer",
        "question" : "What State is Seattle located in?",
        "answer" : "Washington"},
                {
        "type" : "single_answer",
        "question" : "Who is the Speaker of the House?",
        "answer" : "Nancy Pelosi"},
                {
        "type" : "single_answer",
        "question" : "What is the Capital of the United Kingdon?",
        "answer" : "London"},

                {
        "type" : "multiple_choice",
        "question" : "What is the Capital of The United States?",
        "answer" : "c",
        "choices" : "a. New York City \n b. Los Angeles \n c. Washington DC \n d. Chicago"},
                {
        "type" : "multiple_choice",
        "question" : "Who is the President of the United States?",
        "answer" : "a",
        "choices" : "a. Donald Trump \n b. Tim Cook \n c. Barack Obama \n d. Bill Gates"},
                 ]
    score = 0
    for i in range(5):
        print("Question "+str(i+1)+": ")
        print(quiz_set[i]["question"])
        if(quiz_set[i]["type"] == "single_answer"):
            ans = input("Enter Answer ")
            if(ans.lower() == quiz_set[i]["answer"].lower()):
                score +=1
                print("Correct")
            else:
                print("Incorrect")
        elif(quiz_set[i]["type"] == "multiple_choice"):
            print("Options:\n", quiz_set[i]["choices"])
            ans = input("Enter correct choice: ")
            if(ans.lower() == quiz_set[i]["answer"].lower()):
                score +=1
                print("Correct")
            else:
                print("Incorrect")
    if(score >= 0 and score <= 2):
        print("Better luck next time.")
    elif(score >= 3 and score <= 4):
        print("Not bad. Try again soon!")
    else:
        print("You Rock")

    print("Thank you for playing!")
    input("Press the <Enter> key to quit.")

main()

Solutions

Expert Solution

OUTPUT:

CODE:

def main():

    print("This Program gives you a quiz and a score after you are done with the quiz")

    quiz_set = [{

        "type" : "single_answer",

        "question" : "What State is Seattle located in?",

        "answer" : "Washington"},

                {

        "type" : "single_answer",

        "question" : "Who is the Speaker of the House?",

        "answer" : "Nancy Pelosi"},

                {

        "type" : "single_answer",

        "question" : "What is the Capital of the United Kingdon?",

        "answer" : "London"},

                {

        "type" : "multiple_choice",

        "question" : "What is the Capital of The United States?",

        "answer" : "c",

        "choices" : "a. New York City \n b. Los Angeles \n c. Washington DC \n d. Chicago"},

                {

        "type" : "multiple_choice",

        "question" : "Who is the President of the United States?",

        "answer" : "a",

        "choices" : "a. Donald Trump \n b. Tim Cook \n c. Barack Obama \n d. Bill Gates"},

                 ]

    score = 0

    playagain = True

    while playagain:

        for i in range(5):

            isSkip = False

            isIncorrect = True

            while not isSkip and isIncorrect:

                print("Question "+str(i+1)+": ")

                print(quiz_set[i]["question"])

                if(quiz_set[i]["type"] == "single_answer"):

                    ans = input("Enter Answer ")

                    if(ans.lower() == quiz_set[i]["answer"].lower()):

                        isIncorrect = False

                        print("Correct")

                    else:

                        if ans == 'skip':

                            isSkip = True

                        else:

                            print("sorry, try again")

                elif(quiz_set[i]["type"] == "multiple_choice"):

                    print("Options:\n", quiz_set[i]["choices"])

                    ans = input("Enter correct choice: ")

                    if(ans.lower() == quiz_set[i]["answer"].lower()):

                        isIncorrect = False

                        print("Correct")

                    else:

                        if ans == 'skip':

                            isSkip = True

                        else:

                            print("sorry, try again")

        op = input('Do you want to play again')

        if op == 'yes':

            playagain = True

        else:

            playagain = False

            

    print("Thank you for playing!")

    input("Press the <Enter> key to quit.")

main()


Related Solutions

Please make the following changes to the following code: #This program takes in the first and...
Please make the following changes to the following code: #This program takes in the first and last name and creates a userID printing first letter of first name and first 7 characters of last name #by Abi Santo #9/20/20 def main(): print("This Program takes your first and last name and makes a User ID") f_name = str(input("Please enter your first name ")).lower() l_name = str(input("Enter your last name: ")).lower() userID = str(f_name[:1]+str(l_name[:7])) print(userID) main() Call the function createUserName(). This function...
C++ How to make this code take a class object instead of int for the vector...
C++ How to make this code take a class object instead of int for the vector queue and be able to enqueue and dequeue the object? #include <iostream> #include <float.h> #include <bits/stdc++.h> using namespace std; void print_queue(queue<int> Q) //This function is used to print queue { while (!Q.empty()) { cout<< Q.front() << " "; Q.pop(); } } int main() { int n = 10; vector< queue<int> > array_queues(n); //Create vector of queues of size 10, each entry has a queue...
Please answer each question to the best of your ability. You must receive a score of...
Please answer each question to the best of your ability. You must receive a score of 100% to pass. 1) EMS calls in with a patient en-route with suspected stroke, and requests guidance for treatment of blood pressure of 210/110. What is the recommended treatment? Elevate the head of the stretcher or place patient in reverse Trendelenberg Place one inch of nitro paste on the patient’s chest No intervention at present 2) Which of the following reflect the protocol for...
Please take this c++ code and make it into java code. /* RecursionPuzzleSolver * ------------ *...
Please take this c++ code and make it into java code. /* RecursionPuzzleSolver * ------------ * This program takes a puzzle board and returns true if the * board is solvable and false otherwise * * Example: board 3 6 4 1 3 4 2 5 3 0 * The goal is to reach the 0. You can move the number of spaces of your * current position in either the positive / negative direction * Solution for this game...
HCS12 Assembly code please. Translate the following code into assembly. Allocate each variable on the stack....
HCS12 Assembly code please. Translate the following code into assembly. Allocate each variable on the stack. Simulate your program and screenshot the final value of the variables in memory. { char A,B,C; int F; A = 2; B = 6; C = - 10; F = (A + B)*C; C = F +10 }
Note: Draw the schematic and code for each of the following question. All question carries equal...
Note: Draw the schematic and code for each of the following question. All question carries equal marks. 1. Design heat control system as follow. Design a system to maintain the temperature of the system at 37 degree celcius.A temperature sensor is attached with the Arduino analog input. A fan (220 volts) and heater (220V) is placed in a room. If temperature is greater than 37 degree, turn the fan on and if temperature is less than 37 turn on heater....
Can anyone make a documentation and comments for the following code? Documentation in doxgen format please....
Can anyone make a documentation and comments for the following code? Documentation in doxgen format please. Thank you! And simple comments for the code. Thank s. template <typename T> bool LinkedList<T> :: search(const T& item) const { // if list is not empty display the items Node<T>* current = first; while (current != NULL) { if (current->info == item) { return true; } current = current->link; } return false; } template <typename T> void LinkedList<T> :: deleteNode(const T& item) {...
As in previous labs, please write the Java code for each of the following exercises in...
As in previous labs, please write the Java code for each of the following exercises in BlueJ. For each exercise, write a comment before the code stating the exercise number. Make sure you are using the appropriate indentation and styling conventions Exercise 1 (15 Points) In BlueJ, create a new project called Lab6 In the project create a class called Company Add instance data (fields) for the company name (a String) and the sales for the current period (a double)...
Use python simulations to answer the following questions. You should be able to make minor modifications...
Use python simulations to answer the following questions. You should be able to make minor modifications to previous simulations to estimate these probabilities: 1) Suppose the pocket contains one fair coin and one two-headed coin. Find the approximate probability that the coin is fair given that it came up heads on the first flip. 2) Suppose the pocket contains one fair coin and one two-headed coin. Find the approximate probability that the coin is fair given that it came up...
Java Code - Please explain each step through comments. Also, make sure Main (P3_13) is separate...
Java Code - Please explain each step through comments. Also, make sure Main (P3_13) is separate from your class BetterRectangle. Lastly, post a picture of your code inside an IDE along with your output. My code is below, needs modification. E9.13The java.awt.Rectangle class of the standard Java library does not supply a method to compute the area or perimeter of a rectangle. Provide a subclass BetterRectangle ofthe Rectangle class that has getPerimeter and getArea methods. Do not add any instance...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT