1
I have a Python 3 script that tries to be a chatbot, where there are several if and elses which are used based on what the user responds to.
The problem is that in all functions, like get_name() or get_age(), those if and Else repeat.
def get_name():
while True:
    global name
    name = question_renderer("What's your name?")
    name = name.lower().capitalize()
    if name == '':
        continue
    elif name.isdigit():
        typing(1)
        print("Please don't type numbers.")
    else:
        list = ["I like your name.", "I always wanted to have that name.", "My friend has the same name."]
        typing(1)
        print(choice(list))
        break
def get_age():
while True:
    try:
        age = int(question_renderer("How old are you, {}?".format(name)))
    except ValueError:
        typing(1)
        print("Please, just type numbers.")
    else:
        if int(age) <= 25:
            typing(2)
            list = ["You're still young.", "Being young is very good.", "Enjoy your youth."]
            print(choice(list))
        elif int(age) > 25:
            typing(1)
            list = ["You're getting old already.", "I hope you have enjoyed your teenage years.", "More bills to pay than friends."]
            print(choice(list))
        break
How do I make it not happen across the code?
Why instead of that continue you do not put an if name != '': and put the Elif as if and Else inside the first if?
– user92257