Very simple number guessing game I created a simple 15-line number guessing game in Python 2.7:

# Guess the number game
username = raw_input("What is your name? -&gt; ")
guess = input("%s, I'm thinking of a number between 1 and 10. -&gt; " % username)

answer = 7 # sets the answer
answer = guess

if guess &lt; 7:
    print "That's too low."

if guess &gt; 7:
    print "That's too high."

if guess == 7:
    print "Good. Thanks for playing."


What is a proper way I could make it a little more efficient?
Contradicting statements


answer = 7 # sets the answer
answer = guess



Here, you are setting a variable only to immediately set it to another value in the very next line, effectively invalidating the first line. This also makes your code confusing: you do that thing you are doing in these lines, and then you start comparing the guess with this magic number 7 (which is was answer used to be).

Also, why is the answer being set to the guess? Those are two completely different things. Instead of what you are doing, to make your code much more understandable, you should get rid of this line:


answer = guess



Then, instead of comparing guess with 7, compare it with answer.

if guess &lt; answer:
    print "That's too low."

if guess &gt; answer:
    print "That's too high."

if guess == answer:
    print "Good. Thanks for playing."


Now your code is much more readable and follows better practices.



elif

Using elif is good because if the first conditional check fails, the rest will not be executed, which speeds up your code. Unfortunately, elif can not be used in every case due to specific code-based reasons.

Luckily for you, your code can use elif. So, instead of having three separate if statements, you should have one with two elifs:

if guess == answer:
    print "Good. Thanks for playing."

elif guess &lt; answer:
    print "That's too low."

else:
    print "That's too high."


I also re-arranged your code. Now, the most unique conditional comes first. And, instead of a final elif, I put an else because if the guess is not greater than or equal to the answer, it has to be less than it.