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
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...
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!!...
Write a design algorithm and a python program which asks the user for the length of...
Write a design algorithm and a python program which asks the user for the length of the three sides of two triangles. It should compute the perimeter of the two triangles and display it. It should also display which triangle has the greater perimeter. If both have the same perimeter it should display that the perimeters are the same. Formula: Perimeter of triangleA = (side1A + side2A +side3A) See the 2 sample outputs. Enter side1 of TriangleA: 2 Enter side2...
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
Write a program in PYTHON, using a while loop, that asks the user to enter the...
Write a program in PYTHON, using a while loop, that asks the user to enter the amount that they have budgeted for the month. The program should then prompt the user to enter their expenses for the month. The program should keep a running total. Once the user has finished entering their expenses the program should then display if the user is over or under budget. The output should display the monthly budget, the total expenses and whether the user...
Write a complete Python program that asks the user for a line of text (not just...
Write a complete Python program that asks the user for a line of text (not just a single word), and then tells the user whether the string is a palindrome (same forward and backward) if you ignore case and non-alphabetic characters. The following methods and functions may be useful: str.upper(), str.isalpha() -> bool, reversed(str) -> sequence, str.find(str) -> int, str.replace(str, str), str.center(int). Unless otherwise specified, they all return a string.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT