0
每当我运行此代码的两个条件,它总是转到else语句。如果满足符号的条件,则输出将始终不兼容。我究竟做错了什么? 标志和SIGN2是十二生肖的变量。我使用星座元素来查看两个符号是否相互兼容。试图有一个if语句
def zodiacCompatibility(sign, sign2):
fire = ["Aries, Leo, Sagittarius"]
earth = ["Capricorn, Taurus, Virgo"]
water = ["Pisces, Cancer, Scorpio"]
air = ["Gemini, Aquarius, Libra"]
if (sign in fire and sign2 in fire):
result = ("The two signs are compatible")
if (sign in earth and sign2 in earth):
result = ("The two signs are compatible")
if (sign in air and sign2 in air):
result = ("The two signs are compatible")
if (sign in water and sign2 in water):
result = ("The two signs are compatible")
if (sign in fire and sign2 in air):
result = ("The two signs are compatible")
if (sign in water and sign2 in earth):
result = ("The two signs are compatible")
if (sign in air and sign2 in fire):
result = ("The two signs are compatible")
if (sign in earth and sign2 in water):
result = ("The two signs are compatible")
else:
result = ("The two signs are not compatible")
finalResult = zodiacCompatibility(sign, sign2)
打印(finalResult)
我决定在elif中有一个条件,或者if和nest在里面。有效。非常感谢。 –
但为什么没有“和”的工作?如果需要满足两个条件,则不使用“和”。 –
“和”在条件语句中起作用,如果两个条件都满足或两个条件都满足,则语句中的任何内容都会被执行。 – PeskyPotato