鱼C论坛

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

[已解决]哪里错了

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

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

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

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

  2. password = 'i love yst'
  3. time =3
  4. while time:
  5.     guess = input()

  6.     while '*' in  guess:
  7.         print("the'*'is not included in password,please enter it again,and you have"+time+"times: ",end=' ')
  8.     if guess != password:
  9.         guess=input()
  10.         print('the password is wrong,please enter again')
  11.         time-=1
  12.         print('you have '+time+'times')
  13.     else:
  14.          print('you are right,entering.....')
  15. print("out of chance")
复制代码

为什么就是不行
最佳答案
2020-1-11 16:09:57
帮楼主把代码改好了:

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

  2. password = 'i love yst'
  3. time = 3
  4. while time:
  5.     guess = input()

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

使用道具 举报

发表于 2020-1-11 16:09:57 | 显示全部楼层    本楼为最佳答案   
帮楼主把代码改好了:

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

  2. password = 'i love yst'
  3. time = 3
  4. while time:
  5.     guess = input()

  6.     if '*' in guess:
  7.         print("the '*' is not included in password, please enter it again, and you have",
  8.               time, "times: ", end='')
  9.     elif guess != password:
  10.         print('the password is wrong, please enter again, and you have', time, "times: ", end="")
  11.         time -= 1
  12.     else:
  13.         print('you are right, entering.....')
  14.         break
  15. else:
  16.     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-5-26 17:08

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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