News Ticker

Menu

Lệnh if trong Python




<Python>Bài 6: If , elif trong Python.



Tạo file: bai6.py

people = 20 #gán giá trị cho biến
cats = 30
dogs = 15


if people < cats:
    print "Too many cats! The world is doomed!"

elif people > cats:
    print "Not many cats! The world is saved!"

else:
    print "people equal cats"

if people > dogs:
    print "The world is dry!"


dogs += 5 # dogs = dogs + 5

if people > dogs:
    print "People are greater than to dogs."

elif people < dogs:
    print "People are less than to dogs."


else:
    print "People are dogs."
Kết quả:

Chúc các bạn thành công!



Share This:

Post Tags:

No Comment to " Lệnh if trong Python "

  • To add an Emoticons Show Icons
  • To add code Use [pre]code here[/pre]
  • To add an Image Use [img]IMAGE-URL-HERE[/img]
  • To add Youtube video just paste a video link like http://www.youtube.com/watch?v=0x_gnfpL3RM