"Tuple index out of range" Error?
<p>I'm not sure what I'm doing wrong here, does anyone know? I keep getting an error that says "Tuple index out of range." I'm following a tutorial for school and I seem to be doing everything right, however I keep getting this error. Any help would be appreciated! Thank you so much.</p>

<pre><code>animal = input("Enter any LARGE animal: ")
smallAnimal = input("Enter any SMALL animal: ")
weapon = input("Enter a sharp weapon: ")

def createDictionary():

    storyDict = dict()
    storyDict['animal'] = animal
    storyDict['smallAnimal'] = smallAnimal
    storyDict['weapon'] = weapon

return storyDict

def main():

    dictionary = createDictionary()

    animalFormat = """Once upon a time, there was a very, very large {animal}. This {animal} was the meanest, baddest, most gruesome {animal} there     was. And one day, a wild {1} had
    stepped on the {animal}'s foot. At that moment, the {1} knew it had messed up. This made the {animal} angry, so he took a {weapon} and STABBED the 
    {smallAnimal}with it! The {smallAnimal} squirmed and fought to get out, but it was no match for the {animal} with a {weapon}.

    The End."""

    withSubstitutions = animalFormat.format(**dictionary)
    print(withSubstitutions)


main()
</code></pre>

<p>In animalFormat, replace:</p>

<pre><code>{1}
</code></pre>

<p>With:</p>

<pre><code>{smallAnimal}
</code></pre>

<p>This change must be made in two places.</p>

<p>Since you are supplying arguments to <code>format</code> with keywords, there is nothing for <code>1</code> to refer to.</p>

<h3>Simpler example</h3>

<p>Observe that this works:</p>

<pre><code>&gt;&gt;&gt; d = {'a':1, 'b':2}
&gt;&gt;&gt; 'Twice {a} is {b}'.format(**d)
'Twice 1 is 2'
</code></pre>

<p>But this does not work:</p>

<pre><code>&gt;&gt;&gt; 'Twice {1} is {b}'.format(**d)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
IndexError: tuple index out of range
</code></pre>

<p>If you are supplying <code>format</code> with keyword arguments, there is nothing for <code>1</code> to refer to.</p>

<p>It is possible to supply both positional arguments and keyword arguments.  For example:</p>

<pre><code>&gt;&gt;&gt; 'Twice {1} is {b}'.format('Arg0', 'ArgOne', **d)
'Twice ArgOne is 2'
</code></pre>

<h3>Complete working code</h3>

<pre><code>animal = input("Enter any LARGE animal: ")
smallAnimal = input("Enter any SMALL animal: ")
weapon = input("Enter a sharp weapon: ")

def createDictionary():

    storyDict = dict()
    storyDict['animal'] = animal
    storyDict['smallAnimal'] = smallAnimal
    storyDict['weapon'] = weapon

    return storyDict

def main():

    dictionary = createDictionary()

    animalFormat = """Once upon a time, there was a very, very large {animal}. This {animal} was the meanest, baddest, most gruesome {animal} there     was. And one day, a wild {smallAnimal} had
    stepped on the {animal}'s foot. At that moment, the {smallAnimal} knew it had messed up. This made the {animal} angry, so he took a {weapon} and STABBED the_
    {smallAnimal}with it! The {smallAnimal} squirmed and fought to get out, but it was no match for the {animal} with a {weapon}.

    The End."""

    withSubstitutions = animalFormat.format(**dictionary)
    print(withSubstitutions)


main()
</code></pre>

<p>Sample run:</p>

<pre><code>Enter any LARGE animal: Lion
Enter any SMALL animal: Mouse
Enter a sharp weapon: knife
Once upon a time, there was a very, very large Lion. This Lion was the meanest, baddest, most gruesome Lion there     was. And one day, a wild Mouse had
    stepped on the Lion's foot. At that moment, the Mouse knew it had messed up. This made the Lion angry, so he took a knife and STABBED the 
    Mousewith it! The Mouse squirmed and fought to get out, but it was no match for the Lion with a knife.

    The End.
</code></pre>

python tuples