为什么代码卡在循环中?

时间:2017-06-07 20:04:03

标签: python loops logic

import random

i = random.uniform(10,100)  # created a random number

number = int(i)

print number

print "Enter your number user(1-100):"

input__no = raw_input("->")

input_no = int(input__no)

while(input_no != number):

    if(input_no>number):
        print "Number entered is greater than generated number."
        print "input ->" , input_no , "\toutput->" , number
        input__no = raw_input("Enter a number again")

    else:
        print "Number entered is smaller than generated number."
        input_no = raw_input("Enter a number again")

print "Awesome this is correct guess"

1 个答案:

答案 0 :(得分:2)

您忘了将输入转换为循环内的int,并且其中一个变量中有额外的_。在两个违规行中更改为:

input_no = int(raw_input("Enter a number again"))