Python - print name shows None
<pre><code>import re
import time
import sys

def main():
    name = getName()
    getOption()
    nameForTicket, done = getTraveling(name)
    price, destination = getWay()
    fare = getFare()
    seat = getSeat()
    age = getAge()
    totalcost = getTotalCost(price, fare, seat, age)
    print("\n" + "Thank you " + name + " for flying us!" + "\n" + "The ticket price is: $" + str(totalcost) + "\n" + "The destination is: " + str(destination) + "\n" + "Ticket is for: " + str(nameForTicket).title())
    main2(name, done)




def getName():
    name = input("Welcome to Tropical Airlines! Please enter your name &gt;&gt;&gt; ")
    if not re.match("^[a-zA-Z ]*$", name):
        print("Error, only letters allowed!")
        getName()
    elif len(name) &gt; 15:
        print("Error, Only 15 characters allowed!")
        getName()
    else:
        print ("Welcome " + name.title())
    return name

def getOption():
    print("(I) Information" + "\n" + "(O) Order" + "\n" + "(E) Exit")
    user_choice = input("Choose one of the following option &gt;&gt;&gt; ")
    if user_choice.upper() == "I":
        displayInfo()
    else:
        if user_choice.upper() == "O":
            return
        else:
            if user_choice.upper() == "E":
                print("Thank you for visiting Tropical Airlines")
                exit()
            else:
                print("Error")
                getOption()


def displayInfo():
    print("Thank you for choosing Tropical Airlines for your air travel needs." + "\n" + "You will be asked questions regarding what type of ticket you would like to purchase as well as destination information." + "\n" + "We also offer 50% discounted fares for children.")
    getOption()


def getTraveling(name):
    option = input("Who is the traveling person?" + "\n" + "(Y) You" + "\n" + "(S) Someone else")
    if option.upper() == "Y":
        nameForTicket = name
        done = True
        return nameForTicket, done
    elif option.upper() == "S":
        nameForTicket = getName2()
        done = False
        return nameForTicket, done
    else:
        print("Error")
        getTraveling(name)

def getName2():
    name2 = input("What is the travelling person name?")
    if not re.match("^[a-zA-Z ]*$", name2):
        print("Error, only letters allowed!")
        getName2()
    elif len(name2) &gt; 15:
        print("Error, Only 15 characters allowed!")
        getName2()
    else:
        return name2




def getWay():
    option = input("What kind of trip?" + "\n" + "(1) One way" + "\n" + "(2) Round trip")
    if option == "1":
        cost, destination = getDest1()
        return cost, destination
    elif option == "2":
        cost, destination = getDest2()
        return cost, destination
    else:
        print("Error")
        getWay()

def getDest1():
    option = input("Choose one of the following destination: " + "\n" + "(C) Cairns -- $200" + "\n" + "(P) Perth -- $250" + "\n" + "(S) Sydney -- $300")
    if option.upper() == "C":
        initialCost = 200
        dest = "Cairns"
        return initialCost, dest
    elif option.upper() == "P":
        initialCost = 250
        dest = "Perth"
        return initialCost, dest
    elif option.upper() == "S":
        initialCost = 300
        dest = "Sydney"
        return initialCost, dest
    else:
        print("Error")
        getDest1()


def getDest2():
    option = input("Choose one of the following destination: " + "\n" + "(C) Cairns -- $300" + "\n" + "(P) Perth -- $400" + "\n" + "(S) Sydney -- $500")
    if option.upper() == "C":
        initialCost = 300
        dest = "Cairns"
        return initialCost, dest
    elif option.upper() == "P":
        initialCost = 400
        dest = "Perth"
        return  initialCost, dest
    elif option.upper() == "S":
        initialCost = 500
        dest = "Sydney"
        return initialCost, dest
    else:
        print("Error")
        getDest2()

def getFare():
    option = input("Choose one of the following type of fare: " + "\n" + "(B) Business -- Extra $200" + "\n" + "(E) Economy -- Extra $50" + "\n" + "(F) Frugal -- Free")
    if option.upper() == "B":
        fare = 200
        return fare
    elif option.upper() == "E":
        fare = 50
        return fare
    elif option.upper() == "F":
        fare = 0
        return fare
    else:
        print("Error")
        getFare()

def getSeat():
    option = input("Choose one of the following type of seat: " + "\n" + "(W) Window -- $20" + "\n" + "(A) Aisle -- $15" + "\n" + "(M)Middle -- $10")
    if option.upper() == "W":
        seat = 20
        return seat
    elif option.upper() == "A":
        seat = 15
        return seat
    elif option.upper() == "M":
        seat = 10
        return seat
    else:
        print("Error")
        getSeat()

def getAge():
    age = int(input("Enter the age, if the age is bellow 17, you will get 50% discount &gt;&gt;&gt; "))
    while age &lt; 6 or age &gt; 100:
        print("Invalid age")
        age= int(input("Enter the valid age &gt;&gt;&gt;"))
    return age


def getTotalCost(price, fare, seat, age):
    if age &lt;18:
        finalCost = (price + fare + seat)/2
    else:
        finalCost = price + fare + seat
    return finalCost


def loading():
    for i in range(101):
        time.sleep(0.02)
        sys.stdout.write("\r%d%%" % i)
        sys.stdout.flush()


def main2(name, done):
    getOption()
    nameForTicket = getTraveling2(name, done)
    price, destination = getWay()
    fare = getFare()
    seat = getSeat()
    age = getAge()
    totalcost = getTotalCost(price, fare, seat, age)
    print("\n" + "Thank you " + name + " for flying us!" + "\n" + "The ticket price is: $" + str(totalcost) + "\n" + "The destination is: " + str(destination) + "\n" + "Ticket is for: " + str(nameForTicket2).title())
    main2(name, done)

def getTraveling2(name, done):
    option = input("Who is the traveling person?" + "\n" + "(Y) You" + "\n" + "(S) Someone else")
    if option.upper() == "Y":
        if done == True:
            print("You have already ordered ticket for you!")
            getTraveling2(name, done)
        elif done == False:
            nameForTicket = name
            done = True
            return nameForTicket, done
    elif option.upper() == "S":
        nameForTicket = getName2()
        return nameForTicket
    else:
        print("Error")
        getTraveling2(name, done)

main()
</code></pre>

<p>Short story I was writing these long codes.</p>

<p>If from <code>def main()</code> in <code>nameForTicket, done = getTraveling(name)</code> I choose Y, the code shows the name in<code>str(nameForTicket).title()</code> for the <code>def main()</code> just fine.</p>

<p>but in <code>def main2():</code> for the function getTraveling2(name, done) if I choose S, the <code>str(nameForTicket2).title()</code> in <code>def main2():</code> will show None.</p>

<p>And the same happens if from <code>main()</code> I choose S, the <code>main2()</code> if I choose S will show none, and if I choose Y, it will display (Name, True)</p>

<p>how to fix it so the name will show based on the input for S?</p>

<p>In <code>main2</code>, change </p>

<p><code>nameForTicket = getTraveling2(name, done)</code> </p>

<p>to </p>

<p><code>nameForTicket2 = getTraveling2(name, done)</code> </p>

<p>because your print statement in <code>main2</code> addresses <code>str(nameForTicket2).title()</code>, which is trying to print the title of <code>nameForTicket2</code> when you set the result of the <code>getTraveling2</code> method to <code>nameForTicket</code> instead. Therefore, the print statement gives you <code>None</code> since <code>nameForTicket2</code> was never really defined.</p>

python function