Guess the number game using jupyter notebook I made a number guessing game in Python 3 using jupyter notebook. I would appreciate it a lot if I could get some feedback on my code.

from random import randint
randnumb = randint(1,100)
guesses = 0
maxGuesses = 5

while guesses &lt; maxGuesses:
    personInput = int(input('What is your guess? '))
    guesses = guesses + 1

    if personInput == randnumb:
        print()
        print('You won! It took you', guesses, 'guess(es)!')
        break

    if personInput &gt; randnumb and guesses != maxGuesses:
        print('Guess lower', '(', maxGuesses - guesses,'guess(es) left)')
        print()

    if personInput &lt; randnumb and guesses != maxGuesses:
        print('Guess higher', '(', maxGuesses - guesses,'guess(es) left)')
        print()

    if guesses == maxGuesses and personInput != randnumb:
        print()
        print('You lost! You ran out of your guesses!')
        print('The answer was', randnumb, '!')
Pretty clean looking code, but let's look at a few ways it could be better or more pythonic:


Use elif statements:

if personInput == randnumb:
    # ...
elif personInput &gt; randnumb:  # You already know they're != at this point
    # ...
elif ...

Use snake case for your variable names. E.g., use person_input instead of personInput (which is camel case), and rand_num instead of randnumb. In that second case, it's also more common to shorten "number" to "num" instead of "numb".
Use format strings instead of print's argument concatenation, e.g.:

print("Guess lower ({} guesses left)".format(max_guesses - guesses))

Check for and handle errors:

try:
    person_input = int(input("What is your guess? "))
except ValueError:
    print("Not sure what you meant by that, please input an integer")
    continue

I prefer to be more safe than sorry when handling my own incrementor, such as guesses, just in case I do something funky that lets it skip over max_guesses:

# Since you "break" on correct answer, we don't need to check that again
if guesses &gt;= max_guesses:
    # ...





EDIT:

One more thing. In Python, to write a script (rather than a module), you should check if __name__ == '__main__': as follows:

from random import randint

def main():
    randnumb = randint(1,100)
    guesses = 0
    maxGuesses = 5

    while guesses &lt; maxGuesses:
        # ...

if __name__ == '__main__':
    main()


This allows for safe code re-use, and makes sure that the code doesn't get run if this file gets imported from another file. It's not technically necessary for a one-file script like you're writing here, but it's a good practice to get into anyway.