'''check addition'''
from random import randint
def checkAddition( a, b ):
ans = int(raw_input("What is %d + %d ? " % (a,b)))
if ans == a + b:
return True
else:
return False
def main():
x = randint(1,100)
y = randint(1,100)
if checkAddition(x,y):
print "Correct"
else:
print "Incorrect"
main()

This is code that simply checks addition but now I have to embed function in a loop generating 2 random numbers between 1 & 100. counting both total no. of questions & no. of correct responses and also continue loop if you wish or exit if not ..

Any help guys Really appreciated ,,

Recommended Answers

All 3 Replies

You should keep one integer trough the main loop that keeps counting till the person quits. and another integer that only adds up if the user gives a correct answer.

total=0
wins=0
main():
    ...
    total+=1
    if user wins:
        wins+=1

something like that, to see if the player wants to quit you can ask on the end of each addition, raw_input("Do you want to stop(y/n)") You get the point?

BTW: Please use code tags, from now on,it's much easier to read..

Thanks Man , really appreciated !!

Thanks Man , really appreciated !!

You're welcome =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.