Okay so I made my own Multiplication Game for my AS Computing course, but I'm running into a number of issues, mainly this occurring around this line:
if ans == result:
print ("That's right -- well done.\n")
solved = solved + 1
else:
print ("No, I'm afraid the answer is %d.\n" % result)
return solved"
The problem seems to present itself. When playing this Multiplication Game any answer that you input, seems to always be incorrect. I've posted the entire of my game below in hopes that someone can help me <3
Thanks in advance!
from random import *
solved = 0
total_num_q = 0
def play(num1, num2, type, solved):
""" The main play function"""
def sp_type():
type = input("Specify the question type: Multiplication: M, Addition :A, Subtraction: S, Division: D: ")
if type not in ['M','A','S','D']:
print("Please input only enter a valid character: ")
return type
type = ""
while type not in ['M','A','S','D']:
type = sp_type()
if type == "M":
ans = input("What's %d times %d? " % (num1, num2))
result = num1 * num2
if type == "A":
ans = input("What's %d plus %d? " % (num1, num2))
result = num1 + num2
if type == "S":
ans = input("What's %d minus %d? " % (num1, num2))
result = num1 - num2
if type == "D":
ans = input("What's %d divided by %d? " % (num1, num2))
result = num1/num2
if ans == result:
print ("That's right -- well done.\n")
solved = solved + 1
else:
print ("No, I'm afraid the answer is %d.\n" % result)
return solved