资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

流程控制-创新互联

1、单条件流程控制

创新互联长期为1000+客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为振兴企业提供专业的成都网站制作、成都做网站、外贸营销网站建设振兴网站改版等技术服务。拥有10多年丰富建站经验和众多成功案例,为您定制开发。

If:

else:

2、多条件的流程控制

If xxx:

print yyy4

elif xxxx:

print yyy3

elif:

print yyy2

else:

print yyy1

eg:修改ex1.py

#!/usr/bin/env python

# _*_ coding = utf-8 _*_

import getpass

name = raw_input('please inputyour username:')

pwd = getpass.getpass('inputyour password:')

print 'the name is:',name

print 'the password is:',pwd

if name == 'huwei' and pwd =='huwei123':

 print 'you login successfully!,welcomehuwei,normal user'

elif name == 'tony' and pwd =='123':

 print 'you login successfully!,welcometony,super user'

elif name == 'humin' and pwd =='123':

 print 'you login successfully!,welcomehumin,superhero user'

else:

 print 'your password is wrong!'

执行结果:

[root@localhost~]# python ex1.py

please input yourusername:huwei

input yourpassword:

the name is:huwei

the password is:huwei123

you loginsuccessfully!,welcome huwei,normal user

[root@localhost~]# python ex1.py

please input yourusername:humin

input yourpassword:

the name is:humin

the password is:123

you loginsuccessfully!,welcome humin,superhero user

[root@localhost~]# vi ex1.py

[root@localhost~]# python ex1.py

please input yourusername:tony

input yourpassword:

the name is: tony

the password is:123

you loginsuccessfully!,welcome tony,super user

[root@localhost~]#

eg:

变种ex1.py:

import getpass

name = raw_input('please inputyour username:')

pwd =getpass.getpass('password:')

if pwd == '123':

 if name == 'tony':

  print 'tony,normal'

 elif name == 'huwei':

  print 'huwei,super'

 elif name == 'humin':

  print 'humin,superhero'

 else:

  print 'password is wrong!'

else:

 print 'password is wrong!'

执行结果:

[root@localhost~]# python ex1.py

please input yourusername:huwei

input yourpassword:

the name is:huwei

the password is:huwei123

you loginsuccessfully!,welcome huwei,normal user

[root@localhost~]# python ex1.py

please input yourusername:humin

input yourpassword:

the name is:humin

the password is:123

you loginsuccessfully!,welcome humin,superhero user

[root@localhost~]# vi ex1.py

[root@localhost~]# python ex1.py

please input yourusername:tony

input yourpassword:

the name is: tony

the password is:123

you loginsuccessfully!,welcome tony,super user

[root@localhost~]#

注:

1.冒号是条件控制的结束

2.同级缩进要一致:IndentationError2

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


本文题目:流程控制-创新互联
URL标题:http://cdkjz.cn/article/dccdes.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220