首页 > 代码库 > Python中的分支条件结构

Python中的分支条件结构

1. if 


1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 user=input(‘Please input your username : ‘)
4 if user==admin:
5     print(Nice)

2. if ... else ...

1  #!/usr/bin/env python
2  #-*- coding:utf-8 -*-
3  user=input(Please input your username : )
4  pass=input(Please input your password: )
5  if user==admin and pass==123456:
6      print(Good)
7  else:
8      print(Bad)

 

3. if ... elif ... else ...

1  #!/usr/bin/env python
2  #-*- coding:utf-8 -*-
3 grade=(prompt=Please input your grade)
4 if grade>=85:
5     print(Great)
6 elif garde<85 and grade>=70:
7     print(Good)
8 else grade<70:
9     print(Bad)

 

Python中的分支条件结构