<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Well, I'm a programming n00b...' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Well, I'm a programming n00b...' posted on the 'Python' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2012 Programmers Heaven</copyright>
    <pubDate>Wed, 23 May 2012 23:56:55 -0700</pubDate>
    <lastBuildDate>Wed, 23 May 2012 23:56:55 -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>Well, I'm a programming n00b...</title>
      <link>http://www.programmersheaven.com/mb/python/414188/414188/well-im-a-programming-n00b/</link>
      <description>I'm taking an Intro to Comp Sci course and Python is the main topic. Right now we were asked to complete this assignment:&lt;br /&gt;
&lt;br /&gt;
Goal: Apply function top down design to a Python slot machine game.&lt;br /&gt;
The slot machines have between 2 and 6 reels and each reel will display one of 10 digits (0, ..., 9). So each spin will return a number with n digits (as many as reels selected). For each spin, the user determines the number of reels and spin = random.randint(0,10**(r-1)).&lt;br /&gt;
&lt;br /&gt;
First, the user is prompted to enter the number of reels, which will not change throughout the game. The user is also prompted to enter the number of tokens and each spin will cost the player 1 token. The game ends when the user opts not to continue or when the user runs out of tokens.&lt;br /&gt;
&lt;br /&gt;
The user hits the jackpot if the weight is equal to the number of reels. The weight is defined as the largest number of the same digits in one number (Ex. 234458 has weight 2 because 4 appears twice). Based on the number of reels and the weight, the user is awarded tokens (given in project but can be arbitrary for now except when weight = 1, award = 0).&lt;br /&gt;
&lt;br /&gt;
For each spin, the user is shown the generated number, the weight, the award, their balance of tokens and are asked if they would like to continue the game.&lt;br /&gt;
&lt;br /&gt;
It has to be a top down design and we must define our own functions. I'm really confused about defining functions in general, especially when it comes to arguments and the return line. Also, a particular aspect of the program that I'm confused about is how to tally the weight. Someone suggested to make an empty list but I'm not sure how to read the spin digit by digit to keep tally of the digits in the empty list. Here is what I have so far(and I don't believe any of it is correct):&lt;br /&gt;
&lt;br /&gt;
from random import randint&lt;br /&gt;
&lt;br /&gt;
def ask(r, tokens):&lt;br /&gt;
    """&lt;br /&gt;
    Asks user for reel and token inputs&lt;br /&gt;
    """&lt;br /&gt;
    r = input ('How many reels? (2, 3, 4, 5, or 6): ')&lt;br /&gt;
    tokens = input ('Give the number of tokens: ')&lt;br /&gt;
    return (r, tokens)&lt;br /&gt;
&lt;br /&gt;
def spin(r, tokens):&lt;br /&gt;
    """&lt;br /&gt;
    Calculates and displays spin&lt;br /&gt;
    """&lt;br /&gt;
    while respond == 'y':&lt;br /&gt;
    spin = randint (0,10**((r)-1))&lt;br /&gt;
    tokens -=1&lt;br /&gt;
    print 'spin '+str('%04d' % spin)+' has weight _ with award _'&lt;br /&gt;
    if tokens &amp;lt;= 0:&lt;br /&gt;
        print ('ending balance: ' + tokens)&lt;br /&gt;
    else:&lt;br /&gt;
        respond = raw_input('your current balance: ' + str(tokens) + ', conintue? (y/n)')&lt;br /&gt;
&lt;br /&gt;
def weight(spin):&lt;br /&gt;
    """&lt;br /&gt;
    Notes each digit in a spin&lt;br /&gt;
    Determines weight based on greatest amount of same number in each spin&lt;br /&gt;
    """&lt;br /&gt;
    L = [0,0,0,0,0,0,0,0,0,0]&lt;br /&gt;
    m = '-&amp;gt; spin %0d' % (spin)&lt;br /&gt;
    if weight == 1:&lt;br /&gt;
        print m + ', has weight 1 with award 0'&lt;br /&gt;
    elif weight == 2:&lt;br /&gt;
        total += weight&lt;br /&gt;
        respond = raw_input('your current balance: ' + str(total) + ', conintue? (y/n)')&lt;br /&gt;
    return (total,spin)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/414188/414188/well-im-a-programming-n00b/</guid>
      <pubDate>Wed, 03 Mar 2010 18:14:29 -0700</pubDate>
      <category>Python</category>
    </item>
  </channel>
</rss>
