Question

[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?"

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

import random as r#to import random library
i=0#iterable
lis = ['what is 2-3',
'what is 3*5?',
'Value of 6+9',
'What is 7-5',
'What is 14/7']#list of simple math questions
ans = [-1,15,15,2,2]#Answers for the given questions
check=[0]*5#To check the question is already asked or not.
score=0#variable to store the score of the user
while(i!=5):#loop to ask 5 questions
c = r.randint(0,4)#generate the random number in the range of questions.
if(check[c]==0):#condition to check if the question is not answered.
print(lis[c])#Ask the question
a = int(input())#Takes the answer from the user.
if(a==ans[c]):#check whether the user's answer is correct or wrong
score=score+1#If the answer is correct it increments the score.
i+=1#to iterate the loop.
check[c]=1#To ensure the question was already asked.
print('Score is',score)#It prints the score.
OUTPUT:-

For any queries please do comment.

Please Like if you are satisfied.

Add a comment
Know the answer?
Add Answer to:
[Using Python] Create a program that uses import random and while loops to generate one random...
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 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...

  • 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 please Create a menu-driven modular program so user can take a 10-question math quiz, Addition...

    Python please Create a menu-driven modular program so user can take a 10-question math quiz, Addition or subtraction, at specified difficulty level. Easy(1-digit), Intermediate(2-digit), and Hard(3-digit). After a quiz, display the quiz type and level, and number of correct questions user answered.

  • THIS IS A PROGRAM FOR PYTHON THIS IS A PROGRAM FOR PYTHON THIS IS A PROGRAM...

    THIS IS A PROGRAM FOR PYTHON THIS IS A PROGRAM FOR PYTHON THIS IS A PROGRAM FOR PYTHON This time, we will write a program that uses functions to parse through all those names in a List object (see below for the "us_counties" list) to count the number of occurrences each vowel (a, e, i, o, u) has in all the names. We want 5 separate answers, one for each vowel. Not looking for output here. All my solution will...

  • python Create a program to open a text file for reading, find the maximum number in...

    python Create a program to open a text file for reading, find the maximum number in the file, determine if that maximum number is even, and write to an output text file. You should either write Yes if the number is even, otherwise write the maximum number. You should note the following: • Your input file must be named input.txt • The input file has one integer number per line • Your output file must be named output.txt • Your...

  • 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...

  • import random def doTest(operation): ## complete your work here ##    # return True for now...

    import random def doTest(operation): ## complete your work here ##    # return True for now return True    responsesCorrect = 0 print("The software will process a test with 10 questions …… ") for compteur in range (10): operation = random.randint(0,1) if doTest(operation) == True: responsesCorrect += 1 print(responsesCorrect, "Correct responses")    if responsesCorrect <= 6 : print("Ask some help from your instructor.") else: print("Congratulations!") Requirement: You must use the format provided below and then complete the fill! Python! Thanks!...

  • USING C LANGUAGE _Design_ a program that asks the user to answer (easy) multiplication problems. It...

    USING C LANGUAGE _Design_ a program that asks the user to answer (easy) multiplication problems. It is up to you how many math problems you want it to present. The numbers should be chosen at random. The program will then display the user stats: - number of problems answered correctly out of the total - percent correct - grade letter (>= 90 is A, >= 80 is B, >= 70 is C, >=60 is D, < 60 is F)   Example...

  • 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...

  • 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