I'm trying define a function that allows me to determine whether two user defined integers is less than 1000. If this is the case, the function should return the the sum total as 'Ans'. However, if the result is larger than 1000, the function returns the sum itself.
When using print() instead of return the solution works. I've tried the below but the function does not output the answer or the sum in any case. Any ideas why?
Side bar, because I'm defining Ans as having a value of 0 at the beginning, when using print(), the code does tend to output the answer and 0, but that's fine at this point.
Ans = 0
def Sum(Num1, Num2):
# Function to determine whether the total of two numbers is greater than 1000
Ans = Num1 + Num2
if Ans < 1000:
return Ans
else:
return "The sum is:", Num1, "+", Num2
Num1 = int(input("Please enter one number:"))
Num2 = int(input("Please enter a second number:"))
Sum(Num1, Num2);
print(Ans)