0

'''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 ,,

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Kruptein
0

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

Edited by Kruptein: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.