Question

In: Computer Science

----------------------------------------------------------------------------------------------------------------IN PYTHON-----------------------------------------------------------------------------------------------------------------------------write a Q

----------------------------------------------------------------------------------------------------------------IN PYTHON-----------------------------------------------------------------------------------------------------------------------------write a Quiz Generator. This program is expected to generate questions for a student, record student answers, displays the answers correctly entered and reports the total time taken by the student to finish the quiz.
a) The program should initialize three variables, one called correct that starts with an int of 0, second called count that also starts with an int of 0 and third called totalquestions that starts with an int of 5 (Hint: Typecast all the initialized variables to int values). The variable correct stores the correct answers entered by the student, count variable counts the number of questions and totalquestions is a constant value for total number of questions that equals 5.


b) Using the python time library, start the timer for the student. Store the value in a variable startTime. (Hint: Use time() method). Display the message “The quiz has started” using a print statement.


c) Using randint() method, generate two single digit integers for each question and store them in num1 and num2 variables. (Hint: use while to loop through totalquestions, generating two random integers (between 0-9) for each question)


d) Ask the student to input the answer to "What is num1 ** num2?" using input() function and save this value in a variable answer. Grade the answer by comparing its value to the actual operation between the two numbers and display the correct answers if the answer entered is wrong. (Hint: The student must enter the answer for num1 raise to the power num2. Then, after grading, using print statements, display the message “You are correct!” for correct answers entered by the student or “You are wrong! Correct answer is…” for wrong answers entered by the student).

e) End the timer for the student. Store the value in a variable endTime. Use totalTime variable to store the total time taken by the student. (Hint: totalTime is the difference value of endTime and startTime).


f) Print the number of points received based on the number of answers correctly entered by the student (Hint: You can display something like this “The number of points received are 3 out of 5”). Also, print the total test time taken by the student in seconds.


g) Ask input from the user if he wants to retake the test or exit. Depending upon the option selected by the user, restart the program again or end it. You can ask the user for input "Do you want to retake the quiz? Type Y/N: ". If the user enters N or stop or exit, end the program using ‘break’. If the user types Y, restart the quiz again. (Hint: use infinite while loop to restart the quiz again).


h) Use the same variable names and print statement examples as given in the question.

Solutions

Expert Solution

The Python code for the above program is given below :-

import random
import time

while True:
    correct = 0
    count = 0
    totalquestions = 5
    startTime = time.time()
    print("The quiz has started")
    while count < totalquestions:
        count += 1
        num1 = random.randint(0, 9)
        num2 = random.randint(0, 9)
        answer = input("What is {} ** {}? ".format(num1, num2))
        if int(answer) == num1 ** num2:
            print("You are correct!")
            correct += 1
        else:
            print("You are wrong! Correct answer is {}".format(num1 ** num2))
    endTime = time.time()
    print("Total Time:{} seconds".format(int(endTime - startTime)))
    print("The number of points received are {} out of {}".format(correct, totalquestions))
    inp = input("Do you want to retake the quiz? Type Y/N: ")
    if inp.lower() == "y" or inp.lower() == "yes":
        continue
    elif inp.lower()=="n" or inp.lower()=="no":
        exit()

Screenshots for above code :-

Output of the above code:-


Related Solutions

In Python, Q. Write a function max_increase(seq) which takes as argument a sequence of numbers and...
In Python, Q. Write a function max_increase(seq) which takes as argument a sequence of numbers and returns the maximum increase from one element in the sequence to an element at a higher index. Assumptions and restrictions: The function must return a number. If there is no increasing pair in the sequence, the function should return 0. This may happen for example if the sequence is decreasing, or if it contains fewer than 2 elements. You can assume that the argument...
Q: Using Python: Am trying to write a code that can be tested. Any assistance will...
Q: Using Python: Am trying to write a code that can be tested. Any assistance will be appreciated. Would want Help in understanding and solving this example from Data Structure & Algorithms (Computer Science) with the steps of the solution to better understand, thanks. The purpose of this assignment is the application of queues. A prime number is a positive integer other than 1 and is divisible only by 1 and itself. For example, 7 is a prime number because...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
Please write in beginner level PYTHON code! Your job is to write a Python program that...
Please write in beginner level PYTHON code! Your job is to write a Python program that asks the user to make one of two choices: destruct or construct. - If the user chooses to destruct, prompt them for an alternade, and then output the 2 words from that alternade. - If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. - You must enforce that the users enter real...
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
In python. Projectile motion: Write a python program that will ask the user for      an...
In python. Projectile motion: Write a python program that will ask the user for      an initial height y0, initial velocity v, launch angle theta, and mass m.      Create two functions, one that will calculate max height      of the projectile, and one that will calculate the range. Ask the     user which one he/she would like to calculate, then present them with the answer. (use kg, m and m/s)
How do I write a script for this in python in REPL or atom, NOT python...
How do I write a script for this in python in REPL or atom, NOT python shell Consider the following simple “community” in Python . . . triangle = [ ["top", [0, 1]], ["bottom-left", [0, 0]], ["bottom-right", [2, 0]], ] This is the calling of function. >>> nearestneighbor([0, 0.6], triangle, myeuclidean) 'top' The new point is (0, 0.6) and the distance function is Euclidean. Now let’s confirm this result . . . >>> myeuclidean([0, 0.6], [0, 1]) 0.4 >>> myeuclidean([0,...
for Python 3 Write a python program that Creates a list that has these values in...
for Python 3 Write a python program that Creates a list that has these values in this order, 'Python', 'JavaScript', and 'PHP' Define a displayMyClasses function that sorts the list and then displays each item on the list, one per line, in sorted order. Also, number the displayed list as shown in the "Running a Sample Program" shown below. Define a guessNext function that selects a random element from the list and returns it to the call of the function....
how to write a unit test for a write function in python? is there a better...
how to write a unit test for a write function in python? is there a better way than running main once and checking whether the new file path exists?
Program must be in Python Write a program in Python whose inputs are three integers, and...
Program must be in Python Write a program in Python whose inputs are three integers, and whose output is the smallest of the three values. Input is 7 15 3
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT