"Guess number" game in Python What could I improve on this code?

from random import randint
guesses = 0
randomNum = (randint(0,100))
numPlayer = 0
while (numPlayer!=randomNum):
    numPlayer = int(input("Guess the number(0-100)"))
    if (numPlayer&gt;randomNum) : 
        print "It's -"  
    elif (numPlayer&lt;randomNum) : print("It's +")
    guesses=guesses+1

print ("Well done you guessed my number in %d guesses" % guesses)
I rewrote your code, let me explain my changes line by line:

from random import randint


The same.

from itertools import count


You need to use modules in Python, itertools is incredibly useful and allows to avoid while and use instead the for loop (manual incrementing is terribly un-idiomatic in Python)

def number_guessing(minimum, maximum):


This is a function, you may use it as many times as you want, even in the same program with different arguments. Taking optional parameters for the messages for ultimate customization is left as an exercise for the reader.

randomNum = randint(minimum, maximum)


We use the parameters as literals in the call to randint, not just numbers.

for tries in count(1):


count() just counts, from 1 (the argument) to infinity. tries is just a number that counts the iterations of a loop, but automatically this time.

numPlayer = int(input("Guess the number({}-{})".format(minimum, maximum))


String interpolation, so the user sees a message that contains the appropraite numbers, not always 0 - 100.

    if numPlayer &gt; randomNum:
        print ("My number is smaller"  )
    elif numPlayer &lt; randomNum:
        print ("My number is bigger")


Using spaces around operators, removing unnecessary parentheses, and using messages that seem more understandable to me. (Your homework will make this messages fully customizable, so if you do not like my choices do not worry)

    elif numPlayer == randomNum:
        return tries


If the player guessed correctly our function halts and returns (gives back) how many tries it took for the user to guess the number.

print ("Well done you guessed my number in {} guesses".format(
    number_guessing(0, 50)))


We just call the function we wrote and print its result, that is how many tries it took.

Final code

Just to play around and implement the change I suggested:

from random import randint
from itertools import count

def number_guessing(minimum, maximum):
    randomNum = randint(minimum, maximum)
    for tries in count(1):
        numPlayer = int(input("Guess the number({}-{})".format(minimum, maximum)))
        if numPlayer &gt; randomNum:
            print ("My number is smaller"  )
        elif numPlayer &lt; randomNum:
            print ("My number is bigger")
        elif numPlayer == randomNum:
            return tries

print ("Well done you guessed my number in {} guesses".format(
    number_guessing(0, 2)))