<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>Python Forum RSS Feed (Replies Included)</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the 'Python' forum at Programmer's Heaven, including replies.</description>
    <language>en</language>
    <copyright>Copyright 2009 Programmers Heaven</copyright>
    <pubDate>Fri, 20 Nov 2009 20:09:56 -0700</pubDate>
    <lastBuildDate>Fri, 20 Nov 2009 20:09:56 -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>Re: Crazy weird symtax errors, please help</title>
      <link>http://www.programmersheaven.com/mb/python/408988/409526/re-crazy-weird-symtax-errors-please-help/#409526</link>
      <description>I'll take another look if you wanna paste code w/ all indentation and what version of python you are using.  It can't be debugged w/o indentation.  Don't worry if it doesn't show up quite right on the page-- I can always hit view page source. As long as it's there :)&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/408988/409526/re-crazy-weird-symtax-errors-please-help/#409526</guid>
      <pubDate>Wed, 18 Nov 2009 11:34:44 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>making a robot arm simulation</title>
      <link>http://www.programmersheaven.com/mb/python/409430/409430/making-a-robot-arm-simulation/</link>
      <description>anybody who knows creating a simulation of a robotic arm in python or in visual basic language....Please help me... you can send your ideas at my e-mail jeff_take143@yahoo.com....thanks....&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/409430/409430/making-a-robot-arm-simulation/</guid>
      <pubDate>Tue, 17 Nov 2009 02:46:29 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Crazy weird symtax errors, please help</title>
      <link>http://www.programmersheaven.com/mb/python/408988/409404/re-crazy-weird-symtax-errors-please-help/#409404</link>
      <description>Okay, this computer is just crazy. it's official.&lt;br /&gt;
My version of Python is officially considered messed up.&lt;br /&gt;
It keeps saying I have a syntax error, but it won't tell me what it is!!!&lt;br /&gt;
A window saying 'syntax error' pops up, but nothing is hi-lighted, and nothing looks out of place!!!&lt;br /&gt;
Come on!!!&lt;br /&gt;
now, you cannot say that Python is interpreting THAT wrong.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/408988/409404/re-crazy-weird-symtax-errors-please-help/#409404</guid>
      <pubDate>Mon, 16 Nov 2009 19:53:42 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: How do I fix this program with value-returning functions?</title>
      <link>http://www.programmersheaven.com/mb/python/408137/409113/re-how-do-i-fix-this-program-with-value-returning-functions/#409113</link>
      <description>In get_playerchoice():&lt;br /&gt;
 -you try to return player__choice, instead of player_choice.&lt;br /&gt;
 -you have while player_choice != (1,2,3), but you expect player choice to be a string.  input() returns strings, so player_choice will never be a tuple.  You want something like player_choice in ('1','2','3')&lt;br /&gt;
&lt;br /&gt;
In determine_winner:&lt;br /&gt;
 -you have player_choice == 2, which will proly be false b/c player_choice is a string&lt;br /&gt;
 -your indentation of the cases for p_choice and c_choice is wrong.  Those are nested loops, so you can't get to c_choice == 2 and p_choice == 3 UNLESS c_choice == 1 and p_choice == 2 are both true.  You proly want those to be at the same indentation level as the first one.  &lt;br /&gt;
&lt;br /&gt;
In winner_status:&lt;br /&gt;
 -you have return x, y, z.  when this returns in main, winner be something like&lt;br /&gt;
winner == (3,18,0) # the compy is beating you :P&lt;br /&gt;
You go on to call computer_count, player_count, and tie_count, but they don't exist in main-- only a 3-tuple named 'winner'.  Either access the values in winner (ie winner[0]...), or assign all the values (ie a, b, c = winner_status(winner)).  &lt;br /&gt;
Also, winner_status takes one argument.  You are calling it with 3.  This will break it.&lt;br /&gt;
&lt;br /&gt;
That's all the easy stuff to pick out.  If there is more, or if there are logical problems, I defer to eblade.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/408137/409113/re-how-do-i-fix-this-program-with-value-returning-functions/#409113</guid>
      <pubDate>Wed, 11 Nov 2009 18:36:27 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Crazy weird symtax errors, please help</title>
      <link>http://www.programmersheaven.com/mb/python/408988/409103/re-crazy-weird-symtax-errors-please-help/#409103</link>
      <description>answer = input("%(d)s %(e)s %(f)s" %('d': "Tell me,", 'e': nickname, 'f': """:&lt;br /&gt;
\tIf two ducks have 5 ducklings, and three of those ducklings have\n&lt;br /&gt;
\t10 ducklings each, how many ducks do you have in total\n"""))&lt;br /&gt;
&lt;br /&gt;
You declared the args to % as a tuple, and not as a dict.  You want a tuple for multiple unnamed args, and a dict for any number of named args.&lt;br /&gt;
&lt;br /&gt;
Also, it tends to help readability if you write out lists of things as such:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
answer = input("%(a)s %(b)s %(c)s" % {'a': "Tell me,",
                                      'b': your_name,
                                      'c': """:
\tIf two ducks have 5 ducklings, and three of those ducklings have\n
\t10 ducklings each, how many ducks do you have in total\n"""))&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Or something like that.  PEP8 insists that you limit your lines to 80 characters whenever possible, so breaking lists or arguments out to separate lines == pretty.&lt;br /&gt;
&lt;br /&gt;
I find that if I have a syntax error somewhere, it usually shows up somewhere besides where the actual error is.  This has to do with how Python is parsing your code.  It thinks that whatever you wrote is legitimate, but as something else.&lt;br /&gt;
&lt;br /&gt;
Also, the answer is 40. :)&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/408988/409103/re-crazy-weird-symtax-errors-please-help/#409103</guid>
      <pubDate>Wed, 11 Nov 2009 11:47:52 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Crazy weird symtax errors, please help</title>
      <link>http://www.programmersheaven.com/mb/python/408988/409053/re-crazy-weird-symtax-errors-please-help/#409053</link>
      <description>snap, I forgot to hilight.&lt;br /&gt;
Well, the syntax error were stuff like the word "you", the character %, and the quote marks ("").&lt;br /&gt;
Outrageous stuff.&lt;br /&gt;
I mean, seriously, something is up with my comp, and I have NO IDEA what it is!!!&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/408988/409053/re-crazy-weird-symtax-errors-please-help/#409053</guid>
      <pubDate>Tue, 10 Nov 2009 19:26:11 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Crazy weird symtax errors, please help</title>
      <link>http://www.programmersheaven.com/mb/python/408988/409052/re-crazy-weird-symtax-errors-please-help/#409052</link>
      <description>Okay, I reformatted it according to bubbatremell's suggestions (Thanks again!) and it is STILL doing crazy stuff:&lt;br /&gt;
&lt;br /&gt;
import random&lt;br /&gt;
&lt;br /&gt;
your_name = input("What is your name?")&lt;br /&gt;
nicknames = ("Fruitcup", "Captain", "Bunny", "Mama", "Dummkopf")&lt;br /&gt;
nickname = random.choice(nicknames)&lt;br /&gt;
or_not = input("Do you mind if I call you %s?" % nickname)&lt;br /&gt;
if or_not == ("yes"):&lt;br /&gt;
    print ("Fine then,", your_name, ".")&lt;br /&gt;
    answer = input("%(a)s %(b)s %(c)s" %{'a': "Tell me,", 'b': your_name, 'c': """:&lt;br /&gt;
    \tIf two ducks have 5 ducklings, and three of those ducklings have\n&lt;br /&gt;
    \t10 ducklings each, how many ducks do you have in total\n"""))&lt;br /&gt;
    if answer == ("50"):&lt;br /&gt;
        your_name += ("sky")&lt;br /&gt;
        print ("Congradulations,", your_name, ". You're smart!")&lt;br /&gt;
        answer_dos = input("Would you like to see the solution?")&lt;br /&gt;
        if answer_dos == ("yes"):&lt;br /&gt;
            print """&lt;br /&gt;
            We have the mother and father duck, the 5 ducklings and their&lt;br /&gt;
            spouses, and the thirty grand-ducklings, a total of 50 ducks.&lt;br /&gt;
            """&lt;br /&gt;
        else:&lt;br /&gt;
            print ("So long then!")&lt;br /&gt;
    else:&lt;br /&gt;
        print ("You are terrible at math. Goodbye!")&lt;br /&gt;
        input ("Please press the enter key to exit.")&lt;br /&gt;
else:&lt;br /&gt;
    print ("HORRAY!")&lt;br /&gt;
    answer = input("%(d)s %(e)s %(f)s" %('d': "Tell me,", 'e': nickname, 'f': """:&lt;br /&gt;
    \tIf two ducks have 5 ducklings, and three of those ducklings have\n&lt;br /&gt;
    \t10 ducklings each, how many ducks do you have in total\n"""))&lt;br /&gt;
    if answer == ("50"):&lt;br /&gt;
        nickname = your_name += ("sky")&lt;br /&gt;
        print ("Congradulations,", nickname, ". You're smart!")&lt;br /&gt;
        answer_dos = input("Would you like to see the solution?")&lt;br /&gt;
        if answer_dos == ("yes"):&lt;br /&gt;
            print """&lt;br /&gt;
            We have the mother and father duck, the 5 ducklings and their&lt;br /&gt;
            spouses, and the thirty grand-ducklings, a total of 50 ducks.&lt;br /&gt;
            """&lt;br /&gt;
        else:&lt;br /&gt;
            print ("So long, then.")&lt;br /&gt;
    else:&lt;br /&gt;
        print ("You are terrible at math.")&lt;br /&gt;
        &lt;br /&gt;
&lt;br /&gt;
All the stuff hi-lighted in red is stuff it's saying is a syntax error.&lt;br /&gt;
I mean, COME ON!!&lt;br /&gt;
Does anyone think that it might be something wrong with my version of python? Like, my comp screwed up the encoding or something?&lt;br /&gt;
Please get back to me on this!!&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/408988/409052/re-crazy-weird-symtax-errors-please-help/#409052</guid>
      <pubDate>Tue, 10 Nov 2009 19:23:58 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Crazy weird symtax errors, please help</title>
      <link>http://www.programmersheaven.com/mb/python/408988/409050/re-crazy-weird-symtax-errors-please-help/#409050</link>
      <description>Okay, thanks for clearing up my math errors and telling me about %s.&lt;br /&gt;
That was reaaaaally helpful!&lt;br /&gt;
ANd I feel stupid now xD&lt;br /&gt;
Thanks again!&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/408988/409050/re-crazy-weird-symtax-errors-please-help/#409050</guid>
      <pubDate>Tue, 10 Nov 2009 18:39:22 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Crazy weird symtax errors, please help</title>
      <link>http://www.programmersheaven.com/mb/python/408988/409047/re-crazy-weird-symtax-errors-please-help/#409047</link>
      <description>I'm not sure why it's coming up as a syntax error w/o the indentation intact, but I can tell you that the input command is only designed to take one arg.  If you really wanna do some fancy string work, I recommend using %s as follows:&lt;br /&gt;
&lt;br /&gt;
or_not = input("Do you mind if I call you %s?" % nickname)&lt;br /&gt;
&lt;br /&gt;
%s lets you insert stuff into strings.  Your input command is interpreting input("stuff", variable, "moar stuff") as three args.  Using %s, you can jam it all into one, input-function-compatible string.  If you need multiple insertions, the stuff following the % must be a tuple:&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; print("%s, %s, %s" % (1, 2, 3))&lt;br /&gt;
1, 2, 3&lt;br /&gt;
&lt;br /&gt;
Also, if you want, you can name your string args:&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; print("%(s)s %(v)s %(o)s" % {'s': 'dogs', 'v': 'eat', 'o': 'birds'})&lt;br /&gt;
dogs eat birds&lt;br /&gt;
&lt;br /&gt;
The % does some other stuff, too, but I only ever use it with 's'.&lt;br /&gt;
&lt;br /&gt;
Also, the answer is 40 b/c the first ducks had 5 ducklings, not 3.&lt;br /&gt;
:P&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/408988/409047/re-crazy-weird-symtax-errors-please-help/#409047</guid>
      <pubDate>Tue, 10 Nov 2009 15:16:21 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Crazy weird symtax errors, please help</title>
      <link>http://www.programmersheaven.com/mb/python/408988/408988/crazy-weird-symtax-errors-please-help/</link>
      <description>Hey, I just got the newest version of python, Python 3.1.&lt;br /&gt;
I am getting the craziest, most out-there syntax errors ever, and I have no idea what to do.&lt;br /&gt;
Okay, here's a section of code that i just wrote to prove how crazy these errors really are:&lt;br /&gt;
&lt;br /&gt;
import random&lt;br /&gt;
&lt;br /&gt;
your_name = input("What is your name?")&lt;br /&gt;
nicknames = ("Fruitcup", "Captain", "Bunny", "Mama", "Dummkopf")&lt;br /&gt;
nickname = random.choice(nicknames)&lt;br /&gt;
or_not = input("Do you mind if I call you", nickname, "?")&lt;br /&gt;
if or_not == ("yes"):&lt;br /&gt;
    print ("Fine &lt;span style="color: Red;"&gt;th&lt;/span&gt;en,", your_name, ".")&lt;br /&gt;
    answer = input("""&lt;br /&gt;
    Answer this &lt;span style="color: Red;"&gt;th&lt;/span&gt;en,&lt;span style="color: Red;"&gt;"&lt;/span&gt;"", your_name, """:&lt;br /&gt;
    \tIf two ducks have 5 ducklings, and three of those ducklings have\n&lt;br /&gt;
    \t10 ducklings each, how many ducks do you have in total\n""")&lt;br /&gt;
    if answer == ("39"):&lt;br /&gt;
        your_name += ("sky")&lt;br /&gt;
        print ("Congratulations&lt;span style="color: Red;"&gt;&lt;/span&gt;,", your_name, ". You're smart!")&lt;br /&gt;
        answer_dos = input("Would you like to see the solution?")&lt;br /&gt;
        if answer_dos == ("yes"):&lt;br /&gt;
            print """&lt;br /&gt;
            We have the mother and father duck, the three ducklings and their&lt;br /&gt;
            spouses, and the thirty grand-ducklings, a total of 39 ducks.&lt;br /&gt;
            """&lt;br /&gt;
        else:&lt;br /&gt;
            print ("So long then!")&lt;br /&gt;
    else:&lt;br /&gt;
        print ("You are terrible at math.")&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
okay, all the things hi-lighted in red are the things that python is saying is a syntax error. the indenting is not right because i copied and pasted it, but you guys get the general idea:&lt;br /&gt;
&lt;br /&gt;
import random&lt;br /&gt;
&lt;br /&gt;
your_name = input("What is your name?")&lt;br /&gt;
nicknames = ("Fruitcup", "Captain", "Bunny", "Mama", "Dummkopf")&lt;br /&gt;
nickname = random.choice(nicknames)&lt;br /&gt;
or_not = input("Do you mind if I call you", nickname, "?")&lt;br /&gt;
if or_not == ("yes"):&lt;br /&gt;
    print ("Fine then,", your_name, ".")&lt;br /&gt;
    answer = input("""&lt;br /&gt;
    Answer this then,""", your_name, """:&lt;br /&gt;
    \tIf two ducks have 5 ducklings, and three of those ducklings have\n&lt;br /&gt;
    \t10 ducklings each, how many ducks do you have in total\n""")&lt;br /&gt;
    if answer == ("39"):&lt;br /&gt;
        your_name += ("sky")&lt;br /&gt;
        print ("Congratulations,", your_name, ". You're smart!")&lt;br /&gt;
        answer_dos = input("Would you like to see the solution?")&lt;br /&gt;
        if answer_dos == ("yes"):&lt;br /&gt;
            print """&lt;br /&gt;
            We have the mother and father duck, the three ducklings and their&lt;br /&gt;
            spouses, and the thirty grand-ducklings, a total of 39 ducks.&lt;br /&gt;
            """&lt;br /&gt;
        else:&lt;br /&gt;
            print ("So long then!")&lt;br /&gt;
    else:&lt;br /&gt;
        print ("You are terrible at math.")&lt;br /&gt;
&lt;br /&gt;
Like, what is up with that!!?!??!?!?!&lt;br /&gt;
&lt;br /&gt;
Okay, I'm pretty new to programming in general. I was a script kiddie with batch files and .vbs for a while, until i decided i wanted to do something besides making lame joke viruses and putting them on my sister's computer. I've had lots of problems so far, but i've been able to work through them all. Except for this. I've put hours into trying to fix this and nothing works. Please, i just need a little help. Even if you only know what not to do, but not nescesarily how to fix the problem, then by all means comment. any and all comments are appreciated. thanks!!&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/408988/408988/crazy-weird-symtax-errors-please-help/</guid>
      <pubDate>Mon, 09 Nov 2009 14:02:32 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Drawing a stick figure?</title>
      <link>http://www.programmersheaven.com/mb/python/408673/408673/drawing-a-stick-figure/</link>
      <description>well basically i have to draw a stick figure for which is my first question... i cant figure out how to draw a horizontal line and also a line at a angle for the legs... here is the code for the first one&lt;br /&gt;
&lt;br /&gt;
def drawStickFigure():&lt;br /&gt;
from graphics import *&lt;br /&gt;
win = GraphWin("Stick figure")&lt;br /&gt;
head = Circle(Point(100, 60), 20)&lt;br /&gt;
head.draw(win)&lt;br /&gt;
body = Line(Point(100, 80), Point(100, 120))&lt;br /&gt;
body.draw(win)&lt;br /&gt;
arms= Line(Point(0, 100), Point(0, 100))&lt;br /&gt;
arms.draw(win)&lt;br /&gt;
&lt;br /&gt;
for the second question i have to draw a circle which is at the centre of the graphics window. the user inputs the radius of the circle and the circle should come. But for some reasn my code doesnt seem to be working please help&lt;br /&gt;
&lt;br /&gt;
def drawCircle():&lt;br /&gt;
    x = input("please enter the radius of the circle: ")&lt;br /&gt;
    centre= Point(100, 100)&lt;br /&gt;
    circle1 = Circle(centre, x)&lt;br /&gt;
    circle1.draw(win)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/408673/408673/drawing-a-stick-figure/</guid>
      <pubDate>Sun, 01 Nov 2009 12:40:10 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: How do I fix this program with value-returning functions?</title>
      <link>http://www.programmersheaven.com/mb/python/408137/408506/re-how-do-i-fix-this-program-with-value-returning-functions/#408506</link>
      <description>fix it to do what?&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/408137/408506/re-how-do-i-fix-this-program-with-value-returning-functions/#408506</guid>
      <pubDate>Wed, 28 Oct 2009 20:32:52 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>How do I fix this program with value-returning functions?</title>
      <link>http://www.programmersheaven.com/mb/python/408137/408137/how-do-i-fix-this-program-with-value-returning-functions/</link>
      <description>import random&lt;br /&gt;
&lt;br /&gt;
def main(get_playerchoice, get_compchoice):&lt;br /&gt;
    play_again = 'yes'&lt;br /&gt;
    while play_again == 'yes':&lt;br /&gt;
        get_playerchoice = player_choice()&lt;br /&gt;
        get_compchoice = computer_choice()&lt;br /&gt;
        winner = winner_status(player_count, tie-count, computer_count)&lt;br /&gt;
    play_again = raw_input ('Do you wanna play again? Enter yes or press any other key: ')&lt;br /&gt;
    print 'Computer wins ', computer_count &lt;br /&gt;
    print 'Player wins ',  player_count&lt;br /&gt;
    print 'tie ', tie_count&lt;br /&gt;
&lt;br /&gt;
def get_compchoice():&lt;br /&gt;
    computer_choice = random.randint(1, 3)&lt;br /&gt;
    return computer_choice&lt;br /&gt;
def get_playerchoice():&lt;br /&gt;
    player_choice = input ('Enter a number between 1 and 3: ')&lt;br /&gt;
    while player_choice != (1,2,3):&lt;br /&gt;
        print 'Number must be between 1 and 3'&lt;br /&gt;
        player_choice = input ('Enter a number between 1 and 3: ')&lt;br /&gt;
    else:    &lt;br /&gt;
        return player__choice&lt;br /&gt;
&lt;br /&gt;
def determine_winner(computer_choice, player_choice):&lt;br /&gt;
    if computer_choice == 1 and player_choice == 2:&lt;br /&gt;
        winner = player&lt;br /&gt;
        if computer_choice == 2 and player_choice == 3:&lt;br /&gt;
            winner = player &lt;br /&gt;
            if computer_choice == 3 and player_choice == 1:&lt;br /&gt;
                winner = player&lt;br /&gt;
            else: &lt;br /&gt;
                winner = computer    &lt;br /&gt;
        else: &lt;br /&gt;
            winner = computer    &lt;br /&gt;
    else: &lt;br /&gt;
        winner = computer&lt;br /&gt;
    return winner&lt;br /&gt;
def winner_status(winner):&lt;br /&gt;
    if winner == player_count:&lt;br /&gt;
        player_count += 1&lt;br /&gt;
    if winner == computer_count:&lt;br /&gt;
        computer_count += 1&lt;br /&gt;
    if winner == tie_count:&lt;br /&gt;
        tie_count += 1&lt;br /&gt;
    return player_count, tie_count, computer_count&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/408137/408137/how-do-i-fix-this-program-with-value-returning-functions/</guid>
      <pubDate>Thu, 22 Oct 2009 17:23:30 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Function Variable</title>
      <link>http://www.programmersheaven.com/mb/python/404247/408133/re-function-variable/#408133</link>
      <description>question is just a string that gets displayed with every call to raw_input.  response is a string that stores the result of the call to raw_input.  They don't really have anything to do with each other.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/404247/408133/re-function-variable/#408133</guid>
      <pubDate>Thu, 22 Oct 2009 13:16:45 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Problem with python program pls helllllp</title>
      <link>http://www.programmersheaven.com/mb/python/388978/406862/re-problem-with-python-program-pls-helllllp/#406862</link>
      <description>This seems a much more elegant solution to me:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
def convert(deg):
	if deg == "1":
		celsius1 = input("Type the celsius degrees to convert them to kelvin: ")
		kel1 = celsius1+273.15
		return kel1

	if deg == "2":
		celsius2 = input("Type the celsius degrees to convert them to farenheit: ")
		far1 = celsius2*1.8+32
		return far1

	if deg == "3":
		kelvin1 = input("Type the kelvin degrees to convert them to celsius: ")
		cel1 = kelvin1-273.15
		return cel1

	if deg == "4":
		kelvin2 = input("Type the kelvin degrees to convert them to farenheit: ")
		far2 = (kelvin2-273.15)*(9/5)+32
		return far2

	if deg == "5":
		farenheit1 = input("Type the farenheit degrees to convert them to celsius: ")
		cel2 = (farenheit1-32)/1.8
		return cel2

	if deg == "6":
		farenheit2 = input("Type the farenheit degrees to convert them to kelvin: ")
		kel2 = (5/9)*(farenheit2-32)+273.15
		return kel2
		
def sentence(convert):
	sentence = convert
	screen_width = 80
	text_width = len(str(sentence))
	box_width = text_width + 6
	left_margin = (screen_width - box_width) // 2

	print
	print ' ' * left_margin + '+' + '-' * (box_width-4) + '+'
	print ' ' * left_margin + '| ' + ' ' * text_width + ' |'
	print ' ' * left_margin + '| ' + str(sentence) + ' |'
	print ' ' * left_margin + '| ' + ' ' * text_width + ' |'
	print ' ' * left_margin + '+' + '-' * (box_width-4) + '+'

def main():
	print "Choose what you want to convert.....(type a number from 1 to 6)"
	print "1 - Celsius-Kelvin"
	print "2 - Celsius-Farenheit"
	print "3 - Kelvin-Celsius"
	print "4 - Kelvin-Farenheit"
	print "5 - Farenheit-Celsius"
	print "6 - Farenheit-Kelvin"

	deg = raw_input("&amp;gt;: ")
	print sentence(convert(deg))

if __name__ == "__main__":
	main()&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/388978/406862/re-problem-with-python-program-pls-helllllp/#406862</guid>
      <pubDate>Wed, 14 Oct 2009 12:01:33 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Function Variable</title>
      <link>http://www.programmersheaven.com/mb/python/404247/404247/function-variable/</link>
      <description>In the follwoing program I am having trouble understanding this function.&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
def ask_yes_no(question):
    """Ask a yes or no question."""
    response = None
    while response not in ("y", "n"):
        response = raw_input(question).lower()
    return response&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Shouldn't question be response, or response be question? I know thought question was just a variable that held that date sent to the function.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;# Tic-Tac-Toe
# Plays the game of tic-tac-toe against a human opponent
   
# global constants
X = "X"
O = "O"
EMPTY = " "
TIE = "TIE"
NUM_SQUARES = 9


def display_instruct():
    """Display game instructions."""  
    print \
    """
    Welcome to the greatest intellectual challenge of all time: Tic-Tac-Toe.  
    This will be a showdown between your human brain and my silicon processor.  

    You will make your move known by entering a number, 0 - 8.  The number 
    will correspond to the board position as illustrated:
    
                    0 | 1 | 2
                    ---------
                    3 | 4 | 5
                    ---------
                    6 | 7 | 8

    Prepare yourself, human.  The ultimate battle is about to begin. \n
    """


def ask_yes_no(question):
    """Ask a yes or no question."""
    response = None
    while response not in ("y", "n"):
        response = raw_input(question).lower()
    return response


def ask_number(question, low, high):
    """Ask for a number within a range."""
    response = None
    while response not in range(low, high):
        response = int(raw_input(question))
    return response


def pieces():
    """Determine if player or computer goes first."""
    go_first = ask_yes_no("Do you require the first move? (y/n): ")
    if go_first == "y":
        print "\nThen take the first move.  You will need it."
        human = X
        computer = O
    else:
        print "\nYour bravery will be your undoing... I will go first."
        computer = X
        human = O
    return computer, human


def new_board():
    """Create new game board."""
    board = []
    for square in range(NUM_SQUARES):
        board.append(EMPTY)
    return board


def display_board(board):
    """Display game board on screen."""
    print "\n\t", board[0], "|", board[1], "|", board[2]
    print "\t", "---------"
    print "\t", board[3], "|", board[4], "|", board[5]
    print "\t", "---------"
    print "\t", board[6], "|", board[7], "|", board[8], "\n"


def legal_moves(board):
    """Create list of legal moves."""
    moves = []
    for square in range(NUM_SQUARES):
        if board[square] == EMPTY:
            moves.append(square)
    return moves


def winner(board):
    """Determine the game winner."""
    WAYS_TO_WIN = ((0, 1, 2),
                   (3, 4, 5),
                   (6, 7, 8),
                   (0, 3, 6),
                   (1, 4, 7),
                   (2, 5, 8),
                   (0, 4, 8),
                   (2, 4, 6))
    
    for row in WAYS_TO_WIN:
        if board[row[0]] == board[row[1]] == board[row[2]] != EMPTY:
            winner = board[row[0]]
            return winner

    if EMPTY not in board:
        return TIE

    return None


def human_move(board, human):
    """Get human move."""  
    legal = legal_moves(board)
    move = None
    while move not in legal:
        move = ask_number("Where will you move? (0 - 8):", 0, NUM_SQUARES)
        if move not in legal:
            print "\nThat square is already occupied, foolish human.  Choose another.\n"
    print "Fine..."
    return move


def computer_move(board, computer, human):
    """Make computer move."""
    # make a copy to work with since function will be changing list
    board = board[:]
    # the best positions to have, in order
    BEST_MOVES = (4, 0, 2, 6, 8, 1, 3, 5, 7)

    print "I shall take square number",
    
    # if computer can win, take that move
    for move in legal_moves(board):
        board[move] = computer
        if winner(board) == computer:
            print move
            return move
        # done checking this move, undo it
        board[move] = EMPTY
    
    # if human can win, block that move
    for move in legal_moves(board):
        board[move] = human
        if winner(board) == human:
            print move
            return move
        # done checkin this move, undo it
        board[move] = EMPTY

    # since no one can win on next move, pick best open square
    for move in BEST_MOVES:
        if move in legal_moves(board):
            print move
            return move


def next_turn(turn):
    """Switch turns."""
    if turn == X:
        return O
    else:
        return X

    
def congrat_winner(the_winner, computer, human):
    """Congratulate the winner."""
    if the_winner != TIE:
        print the_winner, "won!\n" 
    else:
        print "It's a tie!\n"

    if the_winner == computer:
        print "As I predicted, human, I am triumphant once more.  \n" \
              "Proof that computers are superior to humans in all regards."

    elif the_winner == human:
        print "No, no!  It cannot be!  Somehow you tricked me, human. \n" \
              "But never again!  I, the computer, so swears it!"

    elif the_winner == TIE:
        print "You were most lucky, human, and somehow managed to tie me.  \n" \
              "Celebrate today... for this is the best you will ever achieve."


def main():
    display_instruct()
    computer, human = pieces()
    turn = X
    board = new_board()
    display_board(board)

    while not winner(board):
        if turn == human:
            move = human_move(board, human)
            board[move] = human
        else:
            move = computer_move(board, computer, human)
            board[move] = computer
        display_board(board)
        turn = next_turn(turn)

    the_winner = winner(board)
    congrat_winner(the_winner, computer, human)


# start the program
main()
raw_input("\n\nPress the enter key to quit.")&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/404247/404247/function-variable/</guid>
      <pubDate>Sat, 10 Oct 2009 09:39:46 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Indexing Strings</title>
      <link>http://www.programmersheaven.com/mb/python/402203/403300/re-indexing-strings/#403300</link>
      <description>Thanks for the help. I really appreciate it.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/402203/403300/re-indexing-strings/#403300</guid>
      <pubDate>Thu, 08 Oct 2009 23:26:59 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Indexing Strings</title>
      <link>http://www.programmersheaven.com/mb/python/402203/403057/re-indexing-strings/#403057</link>
      <description>I'm not quite sure how to explain this if you already have it written out as 'word' and 'position'.  Given a string "word" and an integer "i", word[i] returns the letter in the ith position.  Remember that Python is zero-indexed, though, so for the word "index", you have &lt;br /&gt;
i -&amp;gt; 0&lt;br /&gt;
n -&amp;gt; 1&lt;br /&gt;
d -&amp;gt; 2&lt;br /&gt;
e -&amp;gt; 3&lt;br /&gt;
x -&amp;gt; 4&lt;br /&gt;
Note that there is not position 5, even though len(word) == 5.&lt;br /&gt;
&lt;br /&gt;
Also, putting '-' in an index has a special meaning in Py.  That makes your index start at the end of the word instead of at the beginning.  So, you get&lt;br /&gt;
&lt;br /&gt;
x -&amp;gt; -1&lt;br /&gt;
e -&amp;gt; -2&lt;br /&gt;
d -&amp;gt; -3&lt;br /&gt;
n -&amp;gt; -4&lt;br /&gt;
i -&amp;gt; -5&lt;br /&gt;
&lt;br /&gt;
That's nice for when you need to get to the back of a string/list, but you don't know how long it is.  I guess you could also use it to count backwards...&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/402203/403057/re-indexing-strings/#403057</guid>
      <pubDate>Thu, 08 Oct 2009 14:43:27 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Indexing Strings</title>
      <link>http://www.programmersheaven.com/mb/python/402203/402203/indexing-strings/</link>
      <description>In the code below, the only part I'M having trouble with is word[position]. I know this is something really simple but I've always had trouble understanding these kinds of statements. I know that it print a random letter (position) from (word). What I don't know is why or how it does that. That's the part that never seems to get explained to me. How can you just put [] around part of a statement and everything just work right? Thanks.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
# Random Access
# Demonstrates string indexing

import random

word = "index"
print "The word is: ", word, "\n"

high = len(word)
low = -len(word)

for i in range(10):
    position = random.randrange(low, high)
    print "word[", position, "]\t", word[position]

raw_input("\n\nPress the enter key to exit.")&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/402203/402203/indexing-strings/</guid>
      <pubDate>Mon, 05 Oct 2009 23:16:02 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>String Indexing</title>
      <link>http://www.programmersheaven.com/mb/python/401898/401898/string-indexing/</link>
      <description>In the code below, the only part I'M having trouble with is word[position]. I know this is something really simple but I've always had trouble understanding these kinds of statements. I know that it print a random letter (position) from (word). What I don't know is &lt;strong&gt;why&lt;/strong&gt; or &lt;strong&gt;how&lt;/strong&gt; it does that. That's the part that never seems to get explained to me. How can you just put [] around part of a statement and everything just work right? Thanks.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;# Random Access
# Demonstrates string indexing

import random

word = "index"
print "The word is: ", word, "\n"

high = len(word)
low = -len(word)

for i in range(10):
    position = random.randrange(low, high)
    print "word[", position, "]\t", word[position]

raw_input("\n\nPress the enter key to exit.")&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/401898/401898/string-indexing/</guid>
      <pubDate>Sat, 03 Oct 2009 12:35:06 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>cheap Affliction clothing,Coogi clothing,Crown Holder clothing</title>
      <link>http://www.programmersheaven.com/mb/python/401344/401344/cheap-affliction-clothingcoogi-clothingcrown-holder-clothing/</link>
      <description>&lt;a href="http://www.shoeshive.com"&gt;http://www.shoeshive.com&lt;/a&gt; whole sale ( www.shoeshive.com ) &lt;br /&gt;
cheap Michael Jackson Memorial brand clothes ( www.shoeshive.com )&lt;br /&gt;
cheap Kids Urban Clothing,( www.shoeshive.com ) &lt;br /&gt;
cheap Christian Audigier,( www.shoeshive.com ) &lt;br /&gt;
cheap hip hop Coogi urban clothing,( www.shoeshive.com ) &lt;br /&gt;
cheap hip hop Ed hardy clothing,( www.shoeshive.com ) &lt;br /&gt;
cheap Diesel urban clothing,( www.shoeshive.com ) &lt;br /&gt;
cheap Lacoste men women clothing,( www.shoeshive.com ) &lt;br /&gt;
cheap Armani urban clothing( www.shoeshive.com ) &lt;br /&gt;
cheap Ralph Lauren clothing,( www.shoeshive.com ) &lt;br /&gt;
cheap Abercrombie Fitch clothing,( www.shoeshive.com ) &lt;br /&gt;
cheap hip hop BBC clothing,( www.shoeshive.com ) &lt;br /&gt;
cheap Burberry urban clothing,( www.shoeshive.com ) &lt;br /&gt;
cheap hip hop Gucci urban clothing( www.shoeshive.com ) &lt;br /&gt;
cheap ,Polo,Blar Label clothing,( www.shoeshive.com ) &lt;br /&gt;
cheap Smet,Crown Holder clothing,( www.shoeshive.com ) &lt;br /&gt;
cheap Dolce Gabbana clothing,( www.shoeshive.com ) &lt;br /&gt;
cheap hip hop Evisu clothing,( www.shoeshive.com ) &lt;br /&gt;
cheap G-Star urban clothing,( www.shoeshive.com ) &lt;br /&gt;
cheap Affliction urban clothing( www.shoeshive.com ) &lt;br /&gt;
 &lt;br /&gt;
 All product top quality with right price, if you interested in our product, please contact us at:&lt;br /&gt;
&lt;br /&gt;
Website: &lt;a href="http://www.shoeshive.com"&gt;http://www.shoeshive.com&lt;/a&gt;&lt;br /&gt;
Mail : shoeshive@yahoo.com.cn&lt;br /&gt;
MSN: shoeshive@hotmail.com&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/401344/401344/cheap-affliction-clothingcoogi-clothingcrown-holder-clothing/</guid>
      <pubDate>Wed, 30 Sep 2009 06:02:36 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Python IDEL</title>
      <link>http://www.programmersheaven.com/mb/python/400503/400503/python-idel/</link>
      <description>Hey, I've just started with python and I'M using python's IDE, IDEL, &amp;amp; Wing IDE. When I read my book on python programming it shows the programs running in a traditional DOS type of window. But neither of my IDEs run my programs in this traditional form and I would prefer that. Can someone tell me what's up and how to fix it? Thanks.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/400503/400503/python-idel/</guid>
      <pubDate>Sat, 26 Sep 2009 16:37:11 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>wholesale ed hardy long sleeve shirts, coogi jeans,affliction hoodies</title>
      <link>http://www.programmersheaven.com/mb/python/400079/400079/wholesale-ed-hardy-long-sleeve-shirts-coogi-jeansaffliction-hoodies/</link>
      <description>Nike air yeezy: &lt;a href="http://www.freedomdotrade.com/product_list.aspx?pcid=378"&gt;http://www.freedomdotrade.com/product_list.aspx?pcid=378&lt;/a&gt;&lt;br /&gt;
Air jordan 2009 : &lt;a href="http://www.freedomdotrade.com/product_list.aspx?pcid=272"&gt;http://www.freedomdotrade.com/product_list.aspx?pcid=272&lt;/a&gt;&lt;br /&gt;
Jordans six rings : &lt;a href="http://www.freedomdotrade.com/product_list.aspx?pcid=110"&gt;http://www.freedomdotrade.com/product_list.aspx?pcid=110&lt;/a&gt; &lt;br /&gt;
Supra : &lt;a href="http://www.freedomdotrade.com/product_list.aspx?pcid=395"&gt;http://www.freedomdotrade.com/product_list.aspx?pcid=395&lt;/a&gt;&lt;br /&gt;
Cheap Jordan 11 : &lt;a href="http://www.freedomdotrade.com/product_list.aspx?pcid=87"&gt;http://www.freedomdotrade.com/product_list.aspx?pcid=87&lt;/a&gt; &lt;br /&gt;
Jordan 9 fusion : &lt;a href="http://www.freedomdotrade.com/product_list.aspx?pcid=106"&gt;http://www.freedomdotrade.com/product_list.aspx?pcid=106&lt;/a&gt; &lt;br /&gt;
Air jordan spizikes: &lt;a href="http://www.freedomdotrade.com/product_list.aspx?pcid=440"&gt;http://www.freedomdotrade.com/product_list.aspx?pcid=440&lt;/a&gt; &lt;br /&gt;
Air jordan fusion 6 : &lt;a href="http://www.freedomdotrade.com/product_list.aspx?pcid=103"&gt;http://www.freedomdotrade.com/product_list.aspx?pcid=103&lt;/a&gt; &lt;br /&gt;
Nike dunks : &lt;a href="http://www.freedomdotrade.com/product_list.aspx?pcid=240"&gt;http://www.freedomdotrade.com/product_list.aspx?pcid=240&lt;/a&gt; &lt;br /&gt;
Ed hardy t-shirts: &lt;a href="http://www.freedomdotrade.com/product_list.aspx?pcid=193"&gt;http://www.freedomdotrade.com/product_list.aspx?pcid=193&lt;/a&gt; &lt;br /&gt;
Ed hardy boots: &lt;a href="http://www.freedomdotrade.com/product_list.aspx?pcid=203"&gt;http://www.freedomdotrade.com/product_list.aspx?pcid=203&lt;/a&gt; &lt;br /&gt;
Timberland boots : &lt;a href="http://www.freedomdotrade.com/product_list.aspx?pcid=260"&gt;http://www.freedomdotrade.com/product_list.aspx?pcid=260&lt;/a&gt; &lt;br /&gt;
Coach handbags: &lt;a href="http://www.freedomdotrade.com/product_list.aspx?pcid=140"&gt;http://www.freedomdotrade.com/product_list.aspx?pcid=140&lt;/a&gt; &lt;br /&gt;
Ed hardy handbags: &lt;a href="http://www.freedomdotrade.com/product_list.aspx?pcid=199"&gt;http://www.freedomdotrade.com/product_list.aspx?pcid=199&lt;/a&gt; &lt;br /&gt;
jordan heel boots: &lt;a href="http://www.freedomdotrade.com/product_list.aspx?pcid=453"&gt;http://www.freedomdotrade.com/product_list.aspx?pcid=453&lt;/a&gt;&lt;br /&gt;
CHI flat irons : &lt;a href="http://www.freedomdotrade.com/product_list.aspx?pcid=455"&gt;http://www.freedomdotrade.com/product_list.aspx?pcid=455&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/400079/400079/wholesale-ed-hardy-long-sleeve-shirts-coogi-jeansaffliction-hoodies/</guid>
      <pubDate>Thu, 24 Sep 2009 17:31:48 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Strings</title>
      <link>http://www.programmersheaven.com/mb/python/399583/399583/strings/</link>
      <description>I can't find the error in the following code, can someone help me out please? I really don't like this python IDE, is there a better one I can use?&lt;br /&gt;
&lt;br /&gt;
Here is the error message I'M getting.&lt;br /&gt;
Traceback (most recent call last):&lt;br /&gt;
  File "&amp;lt;pyshell#14&amp;gt;", line 1, in -toplevel-&lt;br /&gt;
    + "\nBut what " + "you don't know," + " is that " + "it's one real" \&lt;br /&gt;
TypeError: bad operand type for unary +&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;# Silly Strings
# Demonstrates string concatenation and repetition


print "You can concatenate two " + "strings with the '+' operator." \

    + "\nBut what " + "you don't know," + " is that " + "it's one real" \
    + "l" + "y" + " long string, created from the concatenation " \
    + "of " + "thirty-two " + "different strings, broken across " \
    + "nice lines." + " Now you are" + " impressed?\n\n" + "See, " \
    + "even newlines can be embedded into a single string, making" \
    + " it look " + "as " + "if " + "it" + "'s " + "got " + "to " \
    + "be" + " multiple strings." + " Okay, now this " + "one " \
    + "long" + "string " + "is over!"

print \
"""
If you really like a string, you can repeat it. For example, who doesn't
like pie? That's right, nobody. But if you really like it, you should
say it liek you mean it:""",

print "Pie" * 10

print "\nNow that's good eating."

raw_input("\n\nPress the enter key to exit.")&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/399583/399583/strings/</guid>
      <pubDate>Wed, 23 Sep 2009 09:30:34 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: raw input("")</title>
      <link>http://www.programmersheaven.com/mb/python/398957/399163/re-raw-input/#399163</link>
      <description>&lt;span style="font-size: x-small;"&gt;&lt;span style="color: Blue;"&gt;the right code is :&lt;br /&gt;
&lt;pre class="sourcecode"&gt;raw_input("press enter to exit")&lt;/pre&gt;&lt;br /&gt;
not :&lt;br /&gt;
&lt;pre class="sourcecode"&gt;raw input("press enter to exit")&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/398957/399163/re-raw-input/#399163</guid>
      <pubDate>Tue, 22 Sep 2009 03:47:58 -0700</pubDate>
      <category>Python</category>
    </item>
  </channel>
</rss>