Question

In: Computer Science

create a program that asks user math questions and keeps track of answers... Python Allow the...

create a program that asks user math questions and keeps track of answers...

Python

  1. Allow the user to decide whether or not to keep playing after each math challenge.

  2. Ensure the user’s answer to each math problem is greater than or equal to zero.

  3. Keep track of how many math problems have been asked and how many have been answered correctly.

  4. When finished, inform the user how they did by displaying the total number of math problems, the number they answered correctly, and their percent correct.

Provide meaningful comments

Solutions

Expert Solution

A_count=0#variable used to count answer
Q_count=0#varible used to count question
flagg="y"#varible used to loop until user set it as N
def add():
global A_count#accessing global variable A_count
import random
a = random.randint(0,1000)#getting random numbers for calculations
b = random.randint(0,1000)
result=a+b
if result<0:
#condition to check whether answer is less than zero if yes calls fuction recursively
#until numbers with postive value is obtained as random number
add()
else:
print("Find ",a,"+",b,"and Enter your Answer")
u_result=int(input())#reads user answer
if(u_result<0):
print("Result cannot be negative ! ! Do again")
add()
elif(u_result==result):#if user answer and calculated answer is same answer is right and the Answer count incremented
print("Right Answer !!")
A_count+=1
else:
print("Wrong Answer !! Right answer is ",result)
def sub():
global A_count
import random
a = random.randint(0,1000)
b = random.randint(0,1000)
result=a-b
if result<0:
sub()
else:
print("Find ",a,"-",b,"and Enter your Answer")
u_result=int(input())
if(u_result<0):
print("Result cannot be negative ! ! Do again")
sub()
elif(u_result==result):
print("Right Answer !!")
A_count+=1
else:
print("Wrong Answer !! Right answer is ",result)
def div():
global A_count
import random
a = random.randint(0,1000)
b = random.randint(0,1000)
result=a/b
if result<0:
div()
else:
print("Find ",a,"/",b,"and Enter your Answer")
u_result=int(input())
if(u_result<0):
print("Result cannot be negative ! ! Do again")
div()
elif(u_result==result):
print("Right Answer !!")
A_count+=1
else:
print("Wrong Answer !! Right answer is ",result)
def mul():
global A_count
import random
a = random.randint(0,1000)
b = random.randint(0,1000)
result=a*b
if result<0:
mul()
else:
print("Find ",a,"*",b,"and Enter your Answer")
u_result=int(input())
if(u_result<0):
print("Result cannot be negative ! ! Do again")
mul()
elif(u_result==result):
print("Right Answer !!")
A_count+=1
else:
print("Wrong Answer !! Right answer is ",result)
while(flagg=="Y" or flagg=="y" ):#loops until user set it with letter other than y
x=0
print("Enter your choice \n")
print("Menu\n1.Addition\n2.Substraction\n3.Division\n4.Multiplication\n5.Exit")
x=int(input())
if x==1:
add()
Q_count+=1
elif x==2:
sub()
Q_count+=1
elif x==3:
div()
Q_count+=1
elif x==4:
mul()
Q_count+=1
elif x==5:
flagg="N"
break;
else:
print("Invalid Entry")
print("Do you want to continue??Y/N")
flagg=input()
if Q_count !=0:
print("Total Number of problems attended : ",Q_count )
print("Right answers : ",A_count)
print("Percentage of Right answer : ",((A_count/Q_count)*100))
else:
print("No Questions Attempted!!")

Output

Enter your choice

Menu
1.Addition
2.Substraction
3.Division
4.Multiplication
5.Exit
1
Find 474 + 929 and Enter your Answer
1403
Right Answer !!
Do you want to continue??Y/N
y
Enter your choice

Menu
1.Addition
2.Substraction
3.Division
4.Multiplication
5.Exit
2
Find 695 - 40 and Enter your Answer
650
Wrong Answer !! Right answer is 655
Do you want to continue??Y/N
1
Total Number of problems attended : 2
Right answers : 1
Percentage of Right answer : 50.0



Related Solutions

Hello! Working with python This program asks user math questions and keeps track of answers... Allow...
Hello! Working with python This program asks user math questions and keeps track of answers... Allow the user to decide whether or not to keep playing after each math challenge. Ensure the user’s answer to each math problem is greater than or equal to zero. Keep track of how many math problems have been asked and how many have been answered correctly. When finished, inform the user how they did by displaying the total number of math problems, the number...
Create a program that keeps track of the following information input by the user: First Name,...
Create a program that keeps track of the following information input by the user: First Name, Last Name, Phone Number, Age Now - let's store this in a multidimensional array that will hold 10 of these contacts. So our multidimensional array will need to be 10 rows and 4 columns. You should be able to add, display and remove contacts in the array. In Java
Create an application that asks a user to answer 5 math questions. JAVA
Create an application that asks a user to answer 5 math questions. JAVA
Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
Python: Write a program that keeps track of a game score and declares the winner when...
Python: Write a program that keeps track of a game score and declares the winner when the game is over. A game is over when either one player scores 10 or more points with at least 2 more points than the opponent. A game is also over when one player scores 7 points and the opponent scores none. The program should begin by asking the names of the two players. Then, it should keep asking who won the point till...
Write a python program that will allow a user to draw by inputting commands. The program...
Write a python program that will allow a user to draw by inputting commands. The program will load all of the commands first (until it reaches command "exit" or "done"), and then create the drawing. Must include the following: change attributes: color [red | green | blue] width [value] heading [value] position [xval] [yval] drawing: draw_axes draw_tri [x1] [y1] [x2] [y2] [x3] [y3 draw_rect [x] [y] [b] [h] draw_poly [x] [y] [n] [s] draw_path [path] random random [color | width...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will first enter a password, then enters the same password again; If the second input is the same as first one, the user successfully creates the password. Print “Well done.”; Otherwise, the user will be directed to repeat the whole process (go to step 1.)
In Python write a program that asks the user to enter the monthly costs for the...
In Python write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
In PYTHON: Write a program that asks for a password from a user and checks if...
In PYTHON: Write a program that asks for a password from a user and checks if it satisfies the conditions: Contains at least one lowercase letter (a-z). Contains at least one uppercase letter (A-Z). Contains at least one digit (0-9). Minimum length 6 characters. Contains no spaces. If the password is valid, then the program prints “password accepted”. Otherwise, it keeps asking for more passwords from the user until a valid password is obtained. Hint: You might like to check...
Program a math quiz on Python Specifications: - The program should ask the user a question...
Program a math quiz on Python Specifications: - The program should ask the user a question and allow the student to enter the answer. If the answer is correct, a message of congratulations should be displayed. If the answer is incorrect, a message showing the correct answer should be displayed. - the program should use three functions, one function to generate addition questions, one for subtraction questions, and one for multiplication questions. - the program should store the questions and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT