Python-Basic knowledge-conditional judgment

Source: Internet
Author: User

1. Simple If/else condition judgment

judge_flow.py

Name = input ("Please input name:")ifName = ='Master':    Print('Hello Master') Password= Input ('Please input password:')    ifPassword = ='abc123':        Print('Access granted.')    Else:        Print('wrong password!')Else:    Print('Invalid user!')

Operation Result:

Please input Name:david
Invalid user!

Please input Name:master
Hello Master
Please input PASSWORD:AAA
Wrong password!

Please input Name:master
Hello Master
Please input password:abc123
Access granted.

2. Multiple condition Judgments

elif statements

judge_flow_multiple.py

age = Int (input ("Input your Age:"))ifAge < 5:    Print('Hi, Baby.')elifAge < 12:    Print('Hi Child.')elifAge < 100:    Print('Hi Mans')Else:    Print('Your Majesty')

Operation Result:

Input your Age:3
Hi, Baby.

Input your age:90
Hi Mans

Input your age:1000
Your Majesty

Python-Basic knowledge-conditional judgment

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.