Maths quiz

python

#1

This is the code so far, me with the help of a few very helpful people have done this so far:
def myFunc():
if operators == 1:
answer = num + num2
question = int(input ("What is %s + %s? " % (num,num2)))
elif operators == 2:
answer = num - num2
question = int(input ("What is %s - %s? " % (num,num2)))
else:
answer = num * num2
question = int(input ("What is %s * %s? " % (num,num2)))

if answer == question:
print("Well done!")
else:
print("Sorry, that is incorrect!")
num = random.randint(1,10)
num2 = random.randint(1,10)
operators = random.randint(1,3)
myFunc()

i still need it to display the score at the end of the program and make it display the name,class and score variables in an exell file for the teachers use, if anyone could help i would greatly appreciate it!

I just don't understand how to make a item of code within a defined function affect something outside of the defined area, if anyone can help then i would greatly appreciate it.
-Ben


#2

@cloudjumper36761,
As indentation, is very important in Python-code

Please re-edit your Post

  • leave one blank-line above of your code
  • select your code in the Post
  • then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.

or even better use
= http://discuss.codecademy.com/t/using-backticks-to-format-your-code/3697


#3

Can you explain further? each student needs to make a x amount of exercises? and then you need the score in a excel file?