Guessing a random number The program asks for a user to set the max number of the range. That number is used to set the max range of a randomly generated number. The program keeps track of the number of guesses. I have taken a couple classes recently on different programming languages. I wrote a Hi/Low program in C a while back and decided to convert it to Python 3. I would appreciate someone looking at the code of the program and give me feedback on what I did good/bad and ways that I could improve.

def tooHigh():
    guess = int(print("Your guess is too high, please try again: "))
    return guess

def tooLow():
    guess = int(print("Your guess is too low, please try again: "))
    return guess

def guessLoop(x):
    guess=x
    counter+=1
    if guess&gt;gennum:
        guess = tooHigh()
    elif guess&lt;gennum:
        guess = tooLow()
    elif guess==gennum:
        print("you guessed it!")
    return guess

import random
range=int(input("Please enter the maximum number of the range you would like to guess within: "))
gennum = random.randrange(range+1)
guess = int(input("Please enter a number within the range: "))
counter =1

if guess==gennum:
    print("Congrats, you guessed right on the first try!")

while not guess==gennum:
    loop(guess)

print("It took you",counter,"guesses to guess correctly.")
Here are a few comments:

1) There are three different places in the code where you ask the user to enter the next number to guess. This is not very readable and will backfire if and when you want to extend this code. It's better to have something like this:

def getNextGuessFromUser(messageToPrint):
    print messageToPrint + '\n'
    return int(input())


Then remove the tooHigh, tooLow and initial guess calls, and replace them with calls to this function. By the way, I'm not sure how your reading of guesses works with the print call; looks like a defect to me.

2) Unnecessary usage of global variables. guess should be generated for the first time inside guessLoop, and not rely on the outer code to initialize it.

3) Double check of the right guess. First, you do it in guessLoop to print the right message, and then again in the main module. Again, all of this should be happening in guessLoop: something like this

def guessRun(rightAnswer):
   counter=1
   guess=getNextGuessFromUser("Please enter a number within the range: ")

   while guess != rightAnswer:
     if guess&gt;rightAnswer:
        guess = getNextGuessFromUser("&lt;Too high message&gt;")
     elif guess&lt;rightAnswer:
        guess = getNextGuessFromUser("&lt;Too low message&gt;")
     counter+=1    

   print("you guessed it!")
   return counter


4) Consider using PEP-8.