鱼C论坛

 找回密码
 立即注册
查看: 1195|回复: 9

[已解决]哪里错了

[复制链接]
发表于 2020-1-11 16:02:32 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
print('please enter the password:',end=' ')

password = 'i love yst'
time =3
while time:
    guess = input()

    while '*' in  guess:
        print("the'*'is not included in password,please enter it again,and you have"+time+"times: ",end=' ')
    if guess != password:
        guess=input()
        print('the password is wrong,please enter again')
        time-=1
        print('you have '+time+'times')
    else:
         print('you are right,entering.....')
print("out of chance")
为什么就是不行
最佳答案
2020-1-11 16:09:57
帮楼主把代码改好了:
print('please enter the password:', end=' ')

password = 'i love yst'
time = 3
while time:
    guess = input()

    if '*' in guess:
        print("the '*' is not included in password, please enter it again, and you have",
              time, "times: ", end='')
    elif guess != password:
        print('the password is wrong, please enter again, and you have', time, "times: ", end="")
        time -= 1
    else:
        print('you are right, entering.....')
        break
else:
    print("out of chance")
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-1-11 16:09:57 | 显示全部楼层    本楼为最佳答案   
帮楼主把代码改好了:
print('please enter the password:', end=' ')

password = 'i love yst'
time = 3
while time:
    guess = input()

    if '*' in guess:
        print("the '*' is not included in password, please enter it again, and you have",
              time, "times: ", end='')
    elif guess != password:
        print('the password is wrong, please enter again, and you have', time, "times: ", end="")
        time -= 1
    else:
        print('you are right, entering.....')
        break
else:
    print("out of chance")
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-1-11 16:11:36 | 显示全部楼层
zltzlt 发表于 2020-1-11 16:09
帮楼主把代码改好了:

while:

else:
是什么意思,没学过
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-1-11 16:18:08 | 显示全部楼层
zltzlt 发表于 2020-1-11 16:09
帮楼主把代码改好了:

---,time,----

-----+time+------有什么区别
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-1-11 16:27:28 | 显示全部楼层

while ... else 是当 while 循环自然终止(不是通过 break 终止)时执行 else 下的语句。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-1-11 16:27:40 | 显示全部楼层
基因突变 发表于 2020-1-11 16:18
---,time,----

-----+time+------有什么区别

.... + time + .... 会报错
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-1-11 23:17:52 | 显示全部楼层
zltzlt 发表于 2020-1-11 16:27
while ... else 是当 while 循环自然终止(不是通过 break 终止)时执行 else 下的语句。

是不是和contiune差不多
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-1-12 08:34:16 | 显示全部楼层
基因突变 发表于 2020-1-11 23:17
是不是和contiune差不多

不是
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-1-14 08:17:46 From FishC Mobile | 显示全部楼层
zltzlt 发表于 2020-1-12 08:34
不是

有什么区别啊
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-1-14 09:53:01 | 显示全部楼层

while ... else 和 continue 没有任何关系,也没有相似的地方
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-6-17 16:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表