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