I have been using Python 3 to learn programming, and this is a very basic task, but I want to gain good programming patterns/habits at the very beginning.The program will first randomly generate a number unknown to the user. The user needs to guess what that number is. The program interacts with the user.import randomrandomNumber = random.randrange(0,100)print(Random number has been generated)guessed = Falsewhile guessed==False:    userInput = int(input(Your guess pleas: ))    if userInput==randomNumber:        guessed = True        print(Well done!)    elif userInput>100:        print(Our guess range is between 0 and 100, please try a bit lower)    elif userInput<0:        print(Our guess range is between 0 and 100, please try a bit higher)    elif userInput>randomNumber:        print(Try one more time, a bit lower)    elif userInput < randomNumber:        print(Try one more time, a bit higher)print(End of program)
Guess the Number game in Python
python;beginner;python 3.x;number guessing game
Follow PEP8PEP8 specifies that variables should be named like functions, using _underscores_ over mixedCase:randomNumber -> random_numberuserInput -> user_inputUse chained comparisonsBuilding on Graipher's point, I would negate the condition and take advantage of Python's chained comparison operators:elif not 0 <= user_input <= 100:    print(Our guess range is between 0 and 100, please try again)Keep your code DRY2 sets of strings in your code are very similar to each other. The conditional branches that bring you there are also similar and compare against the same variables.In those cases, you can combine the branch conditions and strings together and branch only at the point when the strings differ, minimizing the duplication between strings. str.format() or the % operator along with conditional expressions are your friends here:elif not 0 <= user_input <= 100:    # Combines 2 branches into 1    print(Our guess range is between 0 and 100, please try a bit {}.    #                                                             ^    # The strings only starts to differ based on the condition here         .format(higher if user_input < 0 else lower))Add compatibility checksAlthough you were only referring to Python 3 for this exercise, it's a good idea to add compatibility for Python 2 for real applications.Simply redefining input() is enough in this simple program:if sys.version_info[0] < 3:    input = raw_inputFor more complicated programs, I suggest you look into six.Group code into functionsThis is helpful even for a small program since it prevents too many variables from polluting the module scope and allows your module to be importable from another program. It's also easier to read and extend later on.(In the example below, you can easily add a range_min and range_max parameter to start_guess() to easily tune the range of numbers to guess from)Use is False instead of == False if necessaryYou should generally avoid direct comparisons to a Boolean and just use not <variable> as Toastrackenigma said if you know the possible values of the variable.However, in cases where the variable value can also be an int, which is probably a sign of bad programming practice anyway, it's better to use is False over == False because 0 == False.(This is not needed in the sample below)Updated code with mine and everyone's suggestions:import randomimport sys# Compatibility with Python 2if sys.version_info[0] < 3:    input = raw_inputdef start_guess():    random_number = random.randrange(0, 101)    print(Random number has been generated.)    while True:        try:            user_input = int(input(Your guess please: ))        except ValueError:            print(Please enter a number.)            continue        if user_input == random_number:            print(Well done!)            break        elif not 0 <= user_input <= 100:    # If it's not between 0 to 100            print(Our guess range is between 0 and 100, please try a bit {}.                # User_input at this point must be outside the range                # so if it's not below the min, it's definitely above the max                 .format(higher if user_input < 0 else lower))        else:            print(Try one more time, a bit {}.                # User_input at this point must be inside the range                # so if it's not below the random_number, it's definitely above it                 .format(higher if user_input < random_number else lower))if __name__ == '__main__':    start_guess()    print(End of program.)