First, the process branch
1. Single branch:
Example 1: Establish a judgment, enter age, determine whether the age is greater than 23, if greater than 23, print the result: ' It is time to find a bf ':
1 age_of _you=int (Input ('please input your name:'))2 age_of _ you=253if age_of _you >:4 print('it is Time to find a BF)
2. Dual branch:
Example 2: Enter a user name and password to welcome the user when the user name and password are correct, otherwise prompt error
1_username='Shanshan'2_password='123456'3 4Username=input ('Pleaue Input your name:')5Password=input ('Pleaue Input your password:')6 7 if_username==username and_password==Password:8 Print('Welcome', username)9 Else:Ten Print('worong username or password')
3. Continue branching under branches
Example 3: Input age, gender, name, if it is a girl, age <28, Output ' I love girls ', age >28, output siblings is also very good oh, if it is boys, output together to make a base bar
1Name=input ('Name:')2Sex=input ('Sex:')3Age=int (Input ("Age :"))4 5 ifsex=='F':6 ifAge<28:7 Print('I Love Girls')8 Else:9 Print('brother and sister Love is also very good oh')Ten Else: One Print('let's do it together.')
4. Multi-Branch
Example 4: a:90~100,b:80~89,c:60~79,d:40~59,e:<39 to Grade,
1Grade=int (Input ('Grade:'))2 3 ifGrade>=90:4 Print('A')5 elifGrade>=80:6 Print('B')7 elifGrade>=60:8 Print('C')9 elifGrade>=40:Ten Print('D') One Else: A Print('E')
Python--if, elif, Else statements