[Solved] Why does my Python program not provide the square for both numbers?


Python uses short-circuiting in logical conditions – in simple words if it determines that there is enough info so that the whole condition is True or False it won’t continue executing the rest of the code in the condition statement – so in your case not all code you intended got executed.

A simple fix for your code to do what you want would be splitting up print statements:

num1 = float(input("Enter the first number: "))
operator = input("Enter an operator: ")
num2 = float(input("Enter the second number: "))



if operator == "+":
    print(num1 + num2)
elif operator == "-":
    print(num1 - num2)
elif operator == "*":
    print(num1 * num2)
elif operator == "/":
    print(num1 / num2)
elif operator == "^":
    print(num1 * num1)
    print(num2 * num2)
else:
    print("Invalid operator")

solved Why does my Python program not provide the square for both numbers?