ITPub博客

首页 > IT职业 > IT生活 > python中的分支有几种形式

python中的分支有几种形式

IT生活 作者:galebird 时间:2021-09-11 10:10:40 0 删除 编辑

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

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

1、if

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

2、 if ... else ...

#!/usr/bin/env python
 #-*- coding:utf-8 -*-
 user=input('Please input your username : ')
 pass=input('Please input your password: ')
 if user=='admin' and pass=='123456':
     print('Good')
 else:
     print('Bad')

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

#!/usr/bin/env python
 #-*- coding:utf-8 -*-
grade=(prompt='Please input your grade')
if grade>=85:
    print('Great')
elif garde<85 and grade>=70:
    print('Good')
else grade<70:
    print('Bad')

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1331/viewspace-2832562/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    92
  • 访问量
    577