I'm trying to have this code return a list item if it's within the index, but if it's not in the index to just default to a specific item in the index
Below code is an example:
messages = ["Hello", "Howdy", "Greetings"]
user_num = int(input("Enter a Number Between 1-3: "))
def message_prompt(num):
    num_check = num - 1
    message = messages[num_check]
    if message in messages:
        print(message)
    else:
        print(messages[2])
message_prompt(user_num)
With this code it just errors out at message because the variable is outside of the scope of the index. What can I do to fix this?
 
     
     
     
    