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')

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM