Learn Python The Hard Way learning (29)-What is If

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.