My code is throwing an error message(That I referenced a variable before I assigned it)


#1

ChipMonkey = "ChipMonkey"
BeariDactyl = "BeariDactyl"
Companions = 0
Energy = 5/5
Question1 = raw_input("What Is Your Name?")
Question2 = raw_input("What Is Your Favorite Color?")
print "So Your Name Is %s, And Your Favorite Color Is %s!" % (Question1,Question2)
WhereWeAreGoing = raw_input("Remind Me Again, %s, Where Are We Going?" % (Question1))
print "Onward, To %s!!!" % (WhereWeAreGoing)

def Fight(Name):
Fight = raw_input("Oh, No! A %s!! We Can A(Fight It, Which will Take Some Of Our Energy, Which Makes It Harder To Win In Later Battles), B(Scare It Away, Which You Can Only Do With A Companion), Or C(Befriend, Which Makes It Harder To Befriend Later, And Gives You Companions To Use For Option B) Which Is Your Choice?"% (Name))
"""Fight Choices Are Here! They Vary By Enemy!!"""

if Fight == "A":

    """This Is The Code For BeariDactyl!!"""
    if Name == "BeariDactyl":
        if Energy > 0:
            print "The Bearidactyl Attacks First, Swooping Down, Roaring. You Dodge, And It Hits A Tree. Fazed, It Runs Away. You Lose Energy."
            Companions = Companions
            Energy = Energy - 1/5
            DoneWith1st = True
        else:
            print "You Cannot Fight! You Died!!"
            Fight(BeariDactyl)

            """This Is The Code For ChipMonkey!!"""
    elif Name == "ChipMonkey":
        if Energy > 0:
            print "The ChipMonkey Attacks First, But You Are Quicker Than It. Your Shield Hits The ChipMonkey. It Runs Away. You Lose Energy."
            Companions = Companions
            Energy = Energy - 1/5
            DoneWith1st = True
        else:
            print "You Cannot Fight! You Died!!"
            Fight(ChipMonkey)


elif Fight == "B":

    """This Is The Code For BeariDactyl!!"""
    if Name == "BeariDactyl":
        if Companions == 1:
            print "Your Companion Scares Away The BeariDactyl, But Is Too Scared To Keep Going With You."
            Companions = Companions - 1
            Energy = Energy + 1/5
        else:
            print "You Cannot Fight! You Died!!"
            Fight(BeariDactyl)

            """This Is The Code For ChipMonkey!!"""
    if Name.lower() == "ChipMonkey":
        if Companions == 1:
            print "Your Companion Scares Away The ChipMonkey, But Is Too Scared To Keep Going With You."
            Companions = Companions - 1
            Energy = Energy + 1/5
        else:
            print "You Cannot Fight! You Died!!"
            Fight(ChipMonkey)


elif Fight == "C":

    """This Is The Code For BeariDactyl!!"""
    if Name == "BeariDactyl":
        if Companions == 0:
            print "You Take Meat From Your Pack And Offer It To The BeariDactyl. He Seems Happy To Lead The Way On The Path As Your Companion!"
            Companions = Companions + 1
            Energy = Energy
        else:
            print "You Can Only Have One Companion At A Time! You Replace Your Current Companion For The BeariDactyl!"
            Companions = Companions
            Energy = Energy

            if Name == "ChipMonkey":
                if Companions == 0:
                    print "You Find A Banana In A Close Tree And Give It To The ChipMonkey. Obviously Pleased, It Runs Up To Your Side!"
                    Companions = Companions + 1
                    Energy = Energy
                else:
                    print "You Can Only Have One Companion At A Time! You Replace Your Current Companion For The ChipMonkey!"
                    Companions = Companions
                    Energy = Energy


print "You Have %s Companions And %s Energy!"% (Companions,Energy)

Fight(ChipMonkey)
if DoneWith1st == True:
Fight(BeariDactyl)


#2

you haven't defined the variable name, yet you are trying to call it in the modulo.

name = #whatever

do this before you define your fight function and you should be good.


#3

Thanks, but doesn't it include that in the definition? Can't you just input the name of what you want the "Name" to be? At the last 3 lines, I call the fight function with the "Chipmonkey" and with the "BeariDactyl".


#4

That is semi-fixed, but it throws the error about energy and companions too. Can I have some help with that too? Here is my revised code.
ChipMonkey = "ChipMonkey"
BeariDactyl = "BeariDactyl"
companions = 0
energy = 1
Question1 = raw_input("What Is Your Name?")
Question2 = raw_input("What Is Your Favorite Color?")
print "So Your Name Is %s, And Your Favorite Color Is %s!" % (Question1,Question2)
WhereWeAreGoing = raw_input("Remind Me Again, %s, Where Are We Going?" % (Question1))
print "Onward, To %s!!!" % (WhereWeAreGoing)

def Fight(Name):
FightChoice = raw_input("Oh, No! A %s!! We Can A(Fight It, Which will Take Some Of Our energy, Which Makes It Harder To Win In Later Battles), B(Scare It Away, Which You Can Only Do With A Companion), Or C(Befriend, Which Makes It Harder To Befriend Later, And Gives You companions To Use For Option B) Which Is Your Choice?"% (Name))
"""Fight Choices Are Here! They Vary By Enemy!!"""

if FightChoice == "A":

    """This Is The Code For BeariDactyl!!"""
    if Name == "BeariDactyl":
        if energy > 0:
            print "The Bearidactyl Attacks First, Swooping Down, Roaring. You Dodge, And It Hits A Tree. Fazed, It Runs Away. You Lose energy."
            companions = companions
            energy = energy - 1/5
            DoneWith1st = True
        else:
            print "You Cannot Fight! You Died!!"
            Fight(BeariDactyl)

            """This Is The Code For ChipMonkey!!"""
    elif Name == "ChipMonkey":
        if energy > 0:
            print "The ChipMonkey Attacks First, But You Are Quicker Than It. Your Shield Hits The ChipMonkey. It Runs Away. You Lose energy."
            companions = companions
            energy = energy - 1/5
            DoneWith1st = True
        else:
            print "You Cannot Fight! You Died!!"
            Fight(ChipMonkey)


elif FightChoice == "B":

    """This Is The Code For BeariDactyl!!"""
    if Name == "BeariDactyl":
        if companions == 1:
            print "Your Companion Scares Away The BeariDactyl, But Is Too Scared To Keep Going With You."
            companions = companions - 1
            energy = energy + 1/5
        else:
            print "You Cannot Fight! You Died!!"
            Fight(BeariDactyl)

            """This Is The Code For ChipMonkey!!"""
    if Name.lower() == "ChipMonkey":
        if companions == 1:
            print "Your Companion Scares Away The ChipMonkey, But Is Too Scared To Keep Going With You."
            companions = companions - 1
            energy = energy + 1/5
        else:
            print "You Cannot Fight! You Died!!"
            Fight(ChipMonkey)


elif FightChoice == "C":

    """This Is The Code For BeariDactyl!!"""
    if Name == "BeariDactyl":
        if companions == 0:
            print "You Take Meat From Your Pack And Offer It To The BeariDactyl. He Seems Happy To Lead The Way On The Path As Your Companion!"
            companions = companions + 1
            energy = energy
        else:
            print "You Can Only Have One Companion At A Time! You Replace Your Current Companion For The BeariDactyl!"
            companions = companions
            energy = energy

            if Name == "ChipMonkey":
                if companions == 0:
                    print "You Find A Banana In A Close Tree And Give It To The ChipMonkey. Obviously Pleased, It Runs Up To Your Side!"
                    companions = companions + 1
                    energy = energy
                else:
                    print "You Can Only Have One Companion At A Time! You Replace Your Current Companion For The ChipMonkey!"
                    companions = companions
                    energy = energy


print "You Have %s companions And %s energy!"% (companions,energy)

Fight("ChipMonkey")
if DoneWith1st == True:
Fight("BeariDactyl")