Question

[Using Python] Create a program to generate one random question, from a list of 5, for...

[Using Python] Create a program to generate one random question, from a list of 5, for each repeated run. Report the number of the correct answers after all five questions have been answered.

Your 5 questions should be a simple math problem, like "what is 5-4?"

  • use a while loop based on the number of questions
    • use a counter variable to count the number of questions asked
    • e.g. questionCount +=1
  • user a counter variable to keep track of the correct answers
    • e.g. correctCount +=1
  • for the questions, generate random numbers between 0 and 9
    • e.g. random_number = random.randint(0, 9
    • you will need "import random" as the first line in your program
  • all questions should be larger number - smaller number
    • i.e. so if the first generated number is 1 and the second 2
    • your question should be 2-1 (not 1-2)

Example:

display "What is 8-2?"

input answer is 2

display "Your answer is incorrect"

display "What is 10-4?"

input answer is 6

display "Your answer is correct"

display "What is 9-4?"

input answer is 4

display "Your answer is correct"

display "What is 2-1?"

input answer is 1

display "Your answer is correct"

display "What is 2-1?"

input answer is 2

display "Your answer is incorrect"

display ""Correct count is 3 out of 5"

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import random
count=0
correct = 0
while count<5:
num1=random.randint(0,9)
num2=random.randint(0,9)
while num2==num1:
num2=random.randint(0,9)
if num1>num2:
result = num1-num2
print("What is",num1,'-',num2,'? ')
answer=int(input(":"))
else:
result = num2-num1
print("What is",num2,'-',num1,'? ')
answer=int(input(":"))
if result==answer:
correct+=1
print("Your answer is correct")
else:
print("Your answer is incorrect")
count+=1
print("Correct count is",correct,"out of 5")

Add a comment
Know the answer?
Add Answer to:
[Using Python] Create a program to generate one random question, from a list of 5, for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • [Using Python] Create a program that uses import random and while loops to generate one random...

    [Using Python] Create a program that uses import random and while loops to generate one random question, from a list of 5, for each repeated run. Report the number of the correct answers after all five questions have been answered. Your 5 questions should be a simple math problem, like "what is 7-5?"

  • For this assignment, write a program that will generate random numbers in the range of 50-100...

    For this assignment, write a program that will generate random numbers in the range of 50-100 and count how many fall into particular ranges. Processing: The program should first seed the random number generator. This is done one time in the program. Use srand(0). Next, generate and display a series of 10 random numbers between 50 and 100. There are several ways to ensure that a random number falls between 50 and 100. One possibility is to use the following...

  • Create a program using the Random class and While loops in Java. The program should generate...

    Create a program using the Random class and While loops in Java. The program should generate a random number from 50 through 100. The loop should add the five random numbers generated. On each iteration of the loop the program should print out the number generated, how many numbers have been generated thus far, and the sum so far. On the last iteration, the printout should say the The final total is.... Teach comment the last time I did it:...

  • Python Program Python: Number Guessing Game Write a Python function called "Guess.py" to create a number...

    Python Program Python: Number Guessing Game Write a Python function called "Guess.py" to create a number guessing game: 1. Function has one input for the number to Guess and one output of the number of attempts needed to guess the value (assume input number will always be between 1 and 1000). 2. If no number was given when the function was called, use random.randint(a,b) to generate a random number between a=1 and b=1000. You will also need to add an...

  • (For Python program)   Write a program that fulfills the functionalities of a mathematical quiz with the...

    (For Python program)   Write a program that fulfills the functionalities of a mathematical quiz with the four basic arithmetic operations, i.e., addition, subtraction, multiplication and integer division. A sample partial output of the math quiz program is shown below. The user can select the type of math operations that he/she would like to proceed with. Once a choice (i.e., menu option index) is entered, the program generates a question and asks the user for an answer. A sample partial output...

  • in c Q3) Write a program to generate three random numbers between 1 and 9 and...

    in c Q3) Write a program to generate three random numbers between 1 and 9 and display them. The user has to enter their sum as soon as possible. These two steps will be repeated continuously. An alarm will be triggered every 5 seconds to display the numb answers so far. If the user did not give a correct answer in 10 seconds, the timer will jump to the main to give an error message "Too slow response!" and terminate...

  • Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements:  The program...

    Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements:  The program should have an array of 5 integers named lottery and should generate a random number in the range of 1 through 99 for each element of the array. The user should enter five digits, which should be stored in an integer array named user. The program is to compare the corresponding elements in the two arrays and keep a count of the digits that...

  • PYTHON Write a program for playing a game with the computer. First, generate a random integer...

    PYTHON Write a program for playing a game with the computer. First, generate a random integer in the range of 6 through 9. This will be the computer’s pick. Then generate three random integers for the human player. These random integers are in the range of 1 through 10. If any of these three random integers is greater than the computer’s pick, the human player wins the game. Otherwise, the human player loses. You must use a for loop to...

  • Design a program using Python and using from flask Import flask that generates a lottery number...

    Design a program using Python and using from flask Import flask that generates a lottery number but in a website.. The program should have an Integer array with 9 elements. Write a loop that steps through the array, randomly generating a number in the range of 0 through 42 for each element. (Use the random function) Then write another loop that displays the contents of the array. Each number should be displayed as a list, the numbers should be generated...

  • CPT 180 Chapter 2 Assignment 3 Directions Using the following guidelines, create a python program. 1....

    CPT 180 Chapter 2 Assignment 3 Directions Using the following guidelines, create a python program. 1. Create a program named printRandomNumbers that gets input from the user and then produces a list of random numbers. 2. Import the random module 3. Add three comment lines at the top of the program that contain: a. Program Name b. Program Description c. Programmer's Name (You) 4. Prompt the user for the following: a. Number of random numbers required b. Lower limit of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT