When setting the if statement condition, I would like to know if there is a way to set the common condition only once with one variable or another.
If you set it as a variable, true false is set as the condition when setting the variable for the first time, so I don't think you can use it as a variable.
# Example of a common variable
if1 = a * b > 0
# Conditional statement 1
a = -1
b = 1
if if1:
# true operation
else:
# false operation
a = 1
b = 1
if if1:
# true operation
else:
# false operation
That's why it's a function.
def both_positive_or_both_negative(a, b):
return a * b > 0
if both_positive_or_both_negative(1, -1):
print("test failed!")
else :
print("test succeeded!")
© 2024 OneMinuteCode. All rights reserved.