I want to ask the user a question that has a default answer, for example:

```
How many apples do you want? [default 40]: 50
You have requested 50 apples.

```

How could this be coded in a neat, robust way that would be usable in Python 2 and 3? How could the way the default value is displayed be made to look something like that shown above?

I have the beginnings of an attempt below:

```
def interrogate_with_default(
    prompt  = None,
    default = None
    ):
    readline.set_startup_hook(lambda: readline.insert_text(default))
    #readline.set_startup_hook(lambda: readline.insert_text(
    #    " [default: {default}]: ".format(
    #        default = default
    #    )
    #))
    try:
        return get_input(prompt)
    finally:
        readline.set_startup_hook()

def get_input(
    prompt = None
    ):
    if sys.version_info >= (3, 0):
        return input(prompt)
    else:
        return raw_input(prompt)

number_of_apples = interrogate_with_default(
    prompt  = "How many apples do you want?",
    default = "40"
)

```