<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Somehow this won't work.' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Somehow this won't work.' posted on the 'Python' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2012 Programmers Heaven</copyright>
    <pubDate>Thu, 24 May 2012 00:06:10 -0700</pubDate>
    <lastBuildDate>Thu, 24 May 2012 00:06:10 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Somehow this won't work.</title>
      <link>http://www.programmersheaven.com/mb/python/416979/416979/somehow-this-wont-work/</link>
      <description>I wanted to do this little program that shows a list of names and give them random numbers. The user have to memorize each name-number set and must give the correct number to the name chosen randomly. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
def mainGame():
    playing = True 


    #The lists are matching names with their numbers.
    nameList = ('Joe', 'Alice', 'Bob', 'Eve')
    #numberList = (returnRandom(0, 10), returnRandom(0, 10), returnRandom(0, 10), returnRandom(0, 10))  #Return random is a function I made that spits out a random number given the range. Shortcut for random.randint(min, max)

    for i in range(0, len(numberList)):
        print nameList[i], ":", numberList[i]

    while playing:
        rand = returnRandom(0, len(numberList))
        
        print "What is %s's number?" % nameList[rand]

        if raw_input("Choice: ") == numberList[rand]:
            playing = False



    print "Congratulation, you finished this minigame !"
&lt;/pre&gt;&lt;br /&gt;
Output:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
Joe : 2
Alice : 10
Bob : 5
Eve : 4

What is Bob's number?
Choice: 5
&lt;/pre&gt;&lt;br /&gt;
(I know I should use a dictionary, but I can't seem to work it out. Any help is appreciated though.)&lt;br /&gt;
&lt;br /&gt;
The problem is that after a few iterations I get this error:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
print "What is %s's number?" % nameList[rand]
IndexError: tuple index out of range
&lt;/pre&gt;&lt;br /&gt;
It can be after 3 iterations, or 5 or 6. And I don't why, its not supposed to go out of range at all ! Halp.&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/416979/416979/somehow-this-wont-work/</guid>
      <pubDate>Wed, 02 Jun 2010 20:46:09 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>This post has been deleted.</title>
      <link>http://www.programmersheaven.com/mb/python/416979/416981/this-post-has-been-deleted/#416981</link>
      <description>This post has been deleted.</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/416979/416981/this-post-has-been-deleted/#416981</guid>
      <pubDate>Thu, 03 Jun 2010 00:45:30 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>This post has been deleted.</title>
      <link>http://www.programmersheaven.com/mb/python/416979/416982/this-post-has-been-deleted/#416982</link>
      <description>This post has been deleted.</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/416979/416982/this-post-has-been-deleted/#416982</guid>
      <pubDate>Thu, 03 Jun 2010 00:46:42 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Somehow this won't work.</title>
      <link>http://www.programmersheaven.com/mb/python/416979/417093/re-somehow-this-wont-work/#417093</link>
      <description>The highest index of a list is len(list) - 1 (b/c it's zero-indexed).&lt;br /&gt;
Say my list looks like this:&lt;br /&gt;
a = [1, 2, 3]&lt;br /&gt;
Then,&lt;br /&gt;
len(a) == 3&lt;br /&gt;
However,&lt;br /&gt;
a[2] == 3&lt;br /&gt;
a[3] == error&lt;br /&gt;
&lt;br /&gt;
In your code, after a while, it tries to hit an index beyond the range of the tuple.  This happens because it's allowed to look up nameList[len(numberList)], but the highest index is len[numberList - 1].&lt;br /&gt;
&lt;br /&gt;
Hope that helps!&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/416979/417093/re-somehow-this-wont-work/#417093</guid>
      <pubDate>Tue, 08 Jun 2010 10:22:46 -0700</pubDate>
      <category>Python</category>
    </item>
  </channel>
</rss>
