guessing numbers from 1 to 8
<p>My program needs to guess the user's number (from 1 to 8) by only asking 3 questions. It prints the first two questions correctly but then when I press enter for the third question, it just prints the last input I did.
How to make all inputs (yes or no) lower case? </p>

<pre><code># Simple Expert System
#firstQuestion = prstr(firstQuestion.lower()) 

print("Think of a number between 1 and 8.")

firstQuestion = (raw_input("Is it an even number? "))
secondQuestion = "Is it less than or equal to 4? "
thirdQuestion = "Is it less than or equal to 3? "
fourthQuestion = "Is it less than 3? "
fifthQuestion = "Is it greater than 6? "
sixthQuestion = "Is it greater than 5? "
seventhQuestion = "Is it less than 2? "




if firstQuestion == "yes":
    print(raw_input(secondQuestion))
elif firstQuestion == "no":
    print(raw_input(thirdQuestion))
elif secondQuestion == "yes":
    print(raw_input(fourthQuestion))
elif secondQuestion == "no":
    print(raw_input(fifthQuestion))
elif thirdQuestion == "no":
    print(raw_input(sixthQuestion))
elif thirdQuestion == "yes":
    print(raw_input(seventhQuestion))

elif fourthQuestion == "yes":
    print("Your number is 2")
elif fourthQuestion == "no":
    print("Your number is 4")

elif fifthQuestion == "yes":
    print("Your number is 8")
elif fifthQuestion == "no":
    print("Your number is 6")   

elif sixthQuestion == "yes":
    print("Your number is 7")
elif sixthQuestion == "no":
    print("Your number is 5")       

elif seventhQuestion == "yes":
    print("Your number is 1")
elif seventhQuestion == "no":
    print("Your number is 3")   
</code></pre>

<p>Consider that your program doesn't scale well at all for larger numbers: if you have to guess a number between 1 and 1000, you're going to have to write a lot of code.</p>

<p>Instead, consider looping through all the ranges that you might get:</p>

<pre><code>lower_limit = 1
upper_limit = 100

while lower_limit &lt; upper_limit:
    middle = int(0.5 * (lower_limit + upper_limit))
    check = raw_input("Larger than " + str(middle) + "? ")
    if check.lower().startswith("y"): # Accept anything that starts with a Y as "yes"
        lower_limit = middle + 1
    else:
        upper_limit = middle

print(lower_limit)
</code></pre>

python python-2.7 python-3.x if-statement