本次練習代碼
people = 20
cats = 30
dogs = 15
if people < cats :
print "Too many cats! The world is doomed!"
if people > cats :
print "Not many cats! The world is saved!"
if people < dogs :
print "The world is drooled on!"
if people > dogs :
print "The world is dry!"
dogs += 5
if people >= dogs :
print "people are greater than or equal to dogs."
if people <= dogs :
print "People are less than or equal to dogs."
if people == dogs :
print "People are dogs."
if語句
格式:
if <布爾表達式> :
代碼段
if語句可以用來在語句後面創建一個代碼段,如果if中的布爾邏輯表達式爲真,則執行其中的代碼段,值得注意的是,if語句冒號後的代碼段必須進行4格縮進,否則會報錯,也就是說,if的冒號後必須有代碼段內容