I have an issue with my hangman maths game where the back end question algorithm says an answer is wrong when it is actually correct. This only seems to happen with negative numbers being multiplied by a positive number. E.g. -4*5 = -20. I have taken my basic algorithm from when i started creating the program to see if it still existed then. And the issue was there. How may I resolve this issue? Here is sample code of the algorithm with all of my GUI code removed:
from tkinter import *
from tkinter import ttk
import random
#says negatives are incorrect when multiplying a negitive by a positive
OP = ['*', '+', '-', '/']
count = 0
range1 = input("Range 1:" )
range1int = int(range1)
range2 = input("Range 2 (must be positive):" )
range2int = int(range2)
while count is 0:
operator = random.choice(OP)
if operator is '/':
num1 = random.randint(1,range2int)
num2 = random.randint(1,range2int)
else:
num1 = random.randint(range1int,range2int)
num2 = random.randint(range1int,range2int)
is_looping = True
if operator is '/':
invalid = num1%num2
while invalid == 0:
num1 = random.randint(1,range2int)
num2 = random.randint(1,range2int)
invalid = num1%num2
if invalid is 0:
is_looping = False
break
if not is_looping:
break
else:
invalid = 0
if invalid is 0:
print("What is ", num1, operator, num2)
question = eval( str(num1) + operator + str(num2))
QuestInt = int(question)
AnsInput = input("Enter Answer (Press Enter When Done):")
IntAns = int(AnsInput)
if IntAns is QuestInt:
print("Correct!")
else:
print("Incorrect")