博客已经搬家到“捕获完成”:
https://www.v2python.com
1、单条件控制
2、多条件控制(这个很重要,掌握了这个,就掌握了上一个的原理和用法)
3、具体的一个例子:
4、接下来,是我自己写的关于一个登陆验证的程序:
#千万要记住要把这个初始的列表放到函数体外
passwd =['change','123456']
def account_login():
input_passwd = input('Please input the passwd:\n')
if input_passwd == passwd[-1]:
print('right,login\n')
elif input_passwd == passwd[0]:
reset_passwd = input('ok,u will reset passwd:\n')
passwd.append(reset_passwd)
print('right,passwd is reseted, new passwd is',passwd[-1])
account_login()
else:
print('wrong,Please re-input the passwd\n')
account_login()
print('Thank you!\n')
account_login()
5、接下来,修改一下,将字符串填空加入进去,修改下面这一句话,显得更简洁专业:
print('right,passwd is reseted, new passwd is',passwd[-1])
#修改为下面一句话
print('right,passwd is reseted, new passwd is:{} \n'.format(passwd[-1])) #对这一句话进行了修改,添加了{}
#千万要记住要把这个初始的列表放到函数体外
passwd =['change','123456']
def account_login():
input_passwd = input('Please input the passwd:\n')
if input_passwd == passwd[-1]:
print('right,login\n')
elif input_passwd == passwd[0]:
reset_passwd = input('ok,u will reset passwd:\n')
passwd.append(reset_passwd)
print('right,passwd is reseted, new passwd is:{} \n'.format(passwd[-1])) #对这一句话进行了修改,添加了{}
account_login()
else:
print('wrong,Please re-input the passwd\n')
account_login()
print('Thank you!\n')
account_login()
参考资料:
小白的第一本python
http://www.runoob.com/python/python-lists.html