Next, we will learn the if statement and enter the following code to ensure proper running.
[Python]
People = 20
Cats = 30
Dogs = 15
If people <cats:
Print "Too success cats! The world is doomed! "
If people> cats:
Print "Not found 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 ."
Running result
Root @ he-desktop :~ /Mystuff # python ex29.py
Too implements cats! The world is doomed!
The world is dry!
People are greater than or equal to dogs.
People are less than or equal to dogs.
People are dogs.
Extra score exercise
Through the above exercises, we can guess the role of the if statement and use our own words to answer the following questions.
1. What do you think if has done to the code below it?
If it is True, the following code is executed; otherwise, the Code is not executed.
2. Why should the code below if be indented with four spaces?
To indicate that the code is included in the if judgment.
3. What will happen if it is not indented?
An indent error is prompted.
4. Can you use some boolean expressions in section 27th to determine if?
5. Change the value of the people, dogs, and cats variables to see what will happen?
Author: lixiang0522