Guess Number

# GuessNumber.py
#
# Guess a number from 1 to 100
#
import random

answer = random.randint(1,100)

print("Number is", answer)

intro = """
I'm thinking of a number from 1 to 100.

Try to guess it in the fewest tries.

Enter your first guess: """ 

def getNumber(prompt):
    n = input(prompt)
    while not n.isdigit():
        n = input("That isn't a number! Try again:")
    return int(n)
        
def nextGuess(n, dir):
    msg = "You guessed " + str(n) +\
        ". That is too " + dir +\
        ".\n\nGuess again:"
    return getNumber(msg)

guess = getNumber(intro)

tries = 1

while not guess == answer:
    if guess > answer:
        direction ="high"
    else:
        direction = "low"
    guess = nextGuess(guess, direction)
    tries += 1

input(f"You guessed it in {tries} tries! Hooray!")