学习测试小脚本:
#!/usr/bin/env python
#coding=utf8
def changePwd(input1,input2='jimmy'):
if input1 == input2:
print "PWD is right!"
return 1
else:
print "Faild."
return 0
def changeNewPwd(input1,input2):
if input1 == input2:
print "Successfully!"
else:
print "Change Error."
if __name__ == '__main__':
oldPwd = raw_input("Pls input your passwd:")
result = changePwd(oldPwd)
while True:
if result:
confirm = raw_input("Could you want to change your password:? if yes,Pls enter 'Y',otherwish,enter 'N':")
if confirm == 'Y':
newpwd1 = raw_input("Pls input new passwd:")
newpwd2 = raw_input("Pls enter again:")
changeNewPwd(newpwd1,newpwd2)
break
elif confirm == 'N':
print "No change!"
break
else:
print "Pls enter the [Y|N]:"
print "Done"
[root@1 ~]# python pwd.py
Pls input your passwd:jimmy
PWD is right!
Could you want to change your password:? if yes,Pls enter 'Y',otherwish,enter 'N':Y
Pls input new passwd:red
Pls enter again:red
Successfully!
Done