For Full Credit answer this in Python and post the answer here please ASAP ! wri
ID: 3542698 • Letter: F
Question
For Full Credit answer this in Python and post the answer here please ASAP !
write the following logic:
randomly generate two numbers
randomly generate one of the 3 choices ("+", "-", "*")
ask the user the a question by combining the two numbers with the random choice.
ask the user to input the answer
call the calculator function that you have defined above to return the result and check if the user's answer is correct.
repeat the above logic three times
print a score that tells the user how many answers out of the three questions were correct.
include division ("/") as a fourth choice however make sure when you ask the question that the result is always a whole number or integer and not a decimal. For example 4/3 is not allowed as the answer is 1.3333 however 4/2 is a valid question as the answer is 2.
Sample
Welcome to my Math test, please enter your name: Ash
Hello Ash, I am going to test your math skills by asking three simple questions. Are you ready (Y/N)
Question 1: What is 3+7?: 9
Incorrect! the correct answer is 10
Question 2: What is 4*5?: 20
Correct!
Question 3: What is 10 - 2?: 7 # make sure that the answer is never negative when you use subtraction
Incorrect! the correct answer is 8
You got 1 out of the 3 questions right
Would you like to play again (Y/N)
Explanation / Answer
def calc():
counttot=0
countcorr=0
while (count<3):
x = random.randint(1,1000)
z=random.randint(1,1000)
y=random.randint(1,4)
if y == 1:
c='+'
elif y==2:
c='-'
elif y==3:
c='*'
else:
c='/'
counttot=counttot+1
a=input()
if c=='+':
d=x+z
elif c=='-':
d=x-z
elif c=='*':
d=x*z
else:
d=x/z
if(a==d):
countcorr=countcorr+1
print ('Correct')
else:
print ("Incorrect')
count=count+1
print ('Welcome to my Math test, please enter your name: ')
name= raw_input()
print ('Hello '+ name+', I am going to test your math skills by asking three simple questions. Are you ready (Y/N)')
in=raw_input()
countcorr=0
counttot=0
count=0
b=raw_input()
if(b=='Y'):
calc();
while(1):
print ('Would you like to play again (Y/N)')
bh=raw_input()
if(bh=='Y'):
calc();
else:
break;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.