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