Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7:此代码不是';不起作用。有什么想法吗?_Python - Fatal编程技术网

Python 2.7:此代码不是';不起作用。有什么想法吗?

Python 2.7:此代码不是';不起作用。有什么想法吗?,python,Python,它应该是一个简单有趣的密码破解程序,但每当我运行它时,它什么也不做。显然没有错误。有什么问题吗 number = 0 password = 200 i = 10 while i == 10: if number != password: number = float(number) + float(1) while i == 10: if number == password: print("Password found, Password i

它应该是一个简单有趣的密码破解程序,但每当我运行它时,它什么也不做。显然没有错误。有什么问题吗

number = 0
password = 200
i = 10

while i == 10:
    if number != password:
        number = float(number) + float(1)
while i == 10:
    if number == password:
         print("Password found, Password is: {1}".format (number))

谢谢

您的代码正在进入一个无限循环,因为
i==10
将始终为真

while i == 10:
    if number != password:
        number = float(number) + float(1)
此循环将永远运行,因为您从未在其中重新定义
i

此外,打印中的字符串格式不正确,因为没有index
{1}
元素。请改为尝试
{0}

print("Password found, Password is: {0}".format (number))

这看起来有问题:

while i == 10:
    if number != password:
        number = float(number) + float(1)
你是说当我=10。。。然而,i的值在您的代码中从未改变,它将是一个无限循环

很难说出你真正想要什么,但你可能正在寻找这样的东西:

>>> number = 0
>>> password = 200
>>> while number != password:
...     number += 1
... 
>>> print("Password found, Password is %d" % number)
Password found, Password is 200

也许可以摆脱整个“i=10”业务

谢谢你的回答!如果你能在你的第一部分写一句简短的话,指出循环不会被留下并永远运行,那就太好了!非常感谢!我很惊讶我没有注意到这个v.v.谢谢你的帮助!哇,谢谢!我一定会记住这一点。我和我的朋友都想不出来。我们对python业务有点陌生。又来了!顺便说一句,您可以使用其他答案中提到的打印格式方法。我喜欢使用%d或%s技术,因为它让我想起了C和许多其他语言。非常感谢,once againIt可能有助于您回答问题,并用伪代码写出您认为程序正在做的事情。仅仅说出来可能会帮助您发现代码中不需要的部分,或者没有做您想要做的事情。