我是橡皮泥 发表于 2018-1-19 17:04:46

大家给我看看是什么问题

设计的密码验证程序,只能验证三次,但是我的这个可以 一直输入下去

sky 发表于 2018-1-19 17:10:00

自己学会调试
在while里加一条打印count的print

BngThea 发表于 2018-1-19 17:12:19

把第3行的
temp = input("请输入密码:")
挪动到循环里 if 的前面
同时去掉else中的最后一行

像番茄加两个蛋 发表于 2018-1-19 17:35:02

您的主要问题是在while 条件上!不能while count: , 应该是while count>=0:就可以了!

Zmynx_2017 发表于 2018-1-19 19:29:05

count = 2
passward = "fish"
temp = input ("请输入密码:")
while count:
    count -= 1
    if (temp == passward):
      print ("输入正确")
      break
    else:
      print("输入错误")
      temp = input ("请重新输入:")你是因为count初值不对,改成2就是循环3次

雪落千寒丶 发表于 2018-1-19 20:00:22

本帖最后由 雪落千寒丶 于 2018-1-19 20:11 编辑

count = 3
passWord="fish"
while count>0:
    print("请输入密码:")
    temp=str(input())
    if temp==passWord:
      print("密码正确!")
      break
    else:
      count-=1
      print("密码错误!你还剩%d次机会"%count)

你把判断条件改一下 就可以正确执行3次了   这是我刚刚写的
页: [1]
查看完整版本: 大家给我看看是什么问题