python登陆代码提示语法错误,求大神指导
这是我借鉴别人的登录界面代码,为什么运行不了啊:'(#!/usr/bin/python
while True:
user = raw_input('Please input username:')
if user == ('Kate'):
password = raw_input('Please input password:')
while True:
if password != ('123'):
print "Wrong password,please try again!"
password = raw_input('Please input password:' )
if password == ('456'):
print "Hello %s,welcome to the system!"% user
break
break
else:
print "The username %s has not been found!" % user
运行时提示syntax erro。
你的代码内容没有问题,八成是代码结构问题:
我给你调了一下,起码不会报错了:
#!/usr/bin/python
while True:
user = raw_input('Please input username:')
if user == ('Kate'):
password = raw_input('Please input password:')
while True:
if password != ('123'):
print "Wrong password,please try again!"
password = raw_input('Please input password1:' )
if password == ('456'):
print "Hello %s,welcome to the system!"% user
break
break
else:
print "The username %s has not been found!" % user
就是逻辑有点理解不了,为什么是这种验证! 地壳 发表于 2015-6-19 14:54
就是逻辑有点理解不了,为什么是这种验证!
刚学python,这是别人写的。我也不懂,看网上基础视频觉得简单,可实际写难度大啊:'(
有没有快速上手的方法呀? 地壳 发表于 2015-6-19 14:53
你的代码内容没有问题,八成是代码结构问题:
我给你调了一下,起码不会报错了:
#!/usr/bin/python
谢谢指导。为什么我输入456显示“Wrong password,please try again!" hu1234 发表于 2015-6-19 15:53
谢谢指导。为什么我输入456显示“Wrong password,please try again!"
while True:
if password != ('123'):
print "Wrong password,please try again!"
password = raw_input('Please input password1:' )
if password == ('456'):
print "Hello %s,welcome to the system!"% user
break
break
python 是用缩进来表示代码块的,你的while里面先判断是不是123,不是就报Wrong password,please try again!,报完这个错后面才是等待输入,你再输一次456就会提示Hello %s,welcome to the system!"% user 了。
页:
[1]