而循环python导致无限循环

时间:2017-07-26 04:56:23

标签: python python-2.7 while-loop

MID()

我是python的初学者,我不知道为什么这个循环会变为无穷大。请有人纠正我的程序

2 个答案:

答案 0 :(得分:1)

原因是因为输入将被评估并设置为字符串。因此,您要比较两种不同类型的变量。您需要将输入转换为整数。

self.ScrollRight()

答案 1 :(得分:1)

def generate_n_chars(n, s = "."):
    res = ""
    count = 0
    while count < n:
        count = count + 1
        res = res + s

    return res

print generate_n_chars(input("Enter the integer value : "), raw_input("Enter the character : "))

此处input("Enter the integer value : ") input代替raw_input

raw_input() =&gt; https://docs.python.org/2/library/functions.html#raw_input

input() =&gt; https://docs.python.org/2/library/functions.html#input