当前位置: 首页 > 图灵资讯 > 行业资讯> python中的分支有几种形式

python中的分支有几种形式

来源:图灵python
时间: 2025-01-02 17:33:29

【相关学习推荐:python教程】

python中的分支有三种形式,分别是:

1、if

#!/usr/bin/envpython
#-*-coding:utf-8-*-
user=input('Pleaseinputyourusername:')
ifuser=='admin':5print('Nice')

2、if ... else ...

#!/usr/bin/envpython
#-*-coding:utf-8-*-
user=input('Pleaseinputyourusername:')
pass=input('Pleaseinputyourpassword:')
ifuser=='admin'andpass=='123456':
print('Good')
else:
print('Bad')

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

#!/usr/bin/envpython
#-*-coding:utf-8-*-
grade=(prompt='Pleaseinputyourgrade')
ifgrade>=85:
print('Great')
elifgarde<85andgrade>=70:
print('Good')
elsegrade<70:
print('Bad')

上一篇:

python中如何创建新表格

下一篇:

返回列表