我正在製作一個項目,並想知道如何使用代碼來判斷用戶是否輸入了「男性」,「女性」,「男性」或「女性」之外的內容。如何判斷用戶是否輸入了男性,男性,女性或女性以外的其他內容?
我使用Python 3.0
這是我的代碼:
import time
def w(t):
if t == t:
time.sleep(t)
print("In the following story, you are a mouse. Please fill out the following information (the story will use this name and gender).")
w(3)
print('\n')
name = input("Your Name:")
w(0.5)
print('\n')
gender = input("Your Gender (Male/Female):")
w(0.5)
print('\n')
input("Press Enter to Begin The Story")
w(1)
print('\n')
print("The Lion and The Mouse")
print("A Short Tale by Aesop")
w(1)
print('\n')
print("Once upon a time in a secluded jungle, there was a mouse.")
w(2)
print('\n')
if gender == ("male" or "Male"):
heorshe = "he"
hisher = "his"
himher = "him"
himselfherself = "himself"
HeShe = "He"
if gender == "female" or "Female":
heorshe = "she"
hisher = "her"
himher = "her"
himselfherself = "herself"
HeShe = "He"
我也想能夠告訴我們,如果用戶在什麼到輸入已進入!請幫忙!
'性別==(「男性」或「男性」):'是不是你怎麼查。你需要將性別與個人進行比較。一個更好的計劃,首先是小寫輸入,然後只檢查「男性」。 – Carcigenicate
另外,'if t == t:'應該完成什麼?我只知道一個會失敗的單一值。 – Carcigenicate
@Carcigenicate謝謝!我會嘗試將答案轉換爲小寫,看看它是否正確運行!但如果你知道如何判斷輸入是空的還是數值的答案,請告訴我! –