我想了解我怎麼能運行下面的Python代碼有道明白真。我猜想評論會做下面的工作。 現在,這只是工作得很好萬一我輸入「真」或「假」大寫首字母。但我也需要得到同樣的結果輸入1或true時等我需要蟒蛇1時,是的,Y鍵入
# Here we ask the user place an input and assign it to name parameter.
name = raw_input ("What is your name human?: ")
# Here we will display the value of name parameter placed by user
print "Got it! Your name is %r" % name
# Here we ask the user if he is owning the device.
# We will assign the answer to computers_owner parameter
computers_owner = input ("Are you the owner of this machine?: ")
# In this question's answer we have an if condition.
# If the answer is True machine will say "Good! I need you" % name
if computers_owner is True:
print "Good! I need you %s" % name
# If the answer is False machine will say "Call me your master!" % name
else:
print "Call me your master! %s" % name
使用的raw_input'()'並且像這樣比較:'computers_owner.lower()==「true」' – MYGz
並且像你提到的那樣添加更多條件'computers_owner.lower()=='true'或computers_owner.lower()=='y'或者computers_owner == 1'。你明白了。 –
用戶爲什麼會想到要* *能夠進入'1'的答案是/否的問題嗎?只需用'y'或'n'檢查一個開始的字符串(忽略大小寫)並完成它。 – chepner