<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ryan Rampersad &#187; Python</title>
	<atom:link href="http://blog.ryanrampersad.com/category/python-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ryanrampersad.com</link>
	<description>Thoughts, Ideas &#38; Opinions</description>
	<lastBuildDate>Thu, 17 May 2012 17:11:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-beta4-20825</generator>
		<item>
		<title>★ Do-While Loop in Python</title>
		<link>http://blog.ryanrampersad.com/2012/04/15/do-while-loop-in-python/</link>
		<comments>http://blog.ryanrampersad.com/2012/04/15/do-while-loop-in-python/#comments</comments>
		<pubDate>Sun, 15 Apr 2012 17:04:59 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[do]]></category>
		<category><![CDATA[loops]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[while]]></category>

		<guid isPermaLink="false">http://blog.ryanrampersad.com/?p=4861</guid>
		<description><![CDATA[There is honestly no do ... while loop in python. But you can simulate the behavior. The do-while loop is useful when the first iteration of a loop will usually suffice, the condition will be met, but not always. You can break out early. It&#8217;s not a perfect do-while clone, but it works great.]]></description>
			<content:encoded><![CDATA[<p>There is honestly no <code>do ... while</code> loop in python. But you can simulate the behavior. The do-while loop is useful when the first iteration of a loop will usually suffice, the condition will be met, but not <em>always</em>. You can <em>break out</em> early.</p>
<pre class="brush: python; title: ; notranslate">
while True:
  if 5 == input(&quot;enter a number, 1-10&quot;):
    print &quot;you got it&quot;
    break
  else:
    print &quot;keep trying&quot;
</pre>
<p>It&#8217;s not a perfect do-while clone, but it works great.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ryanrampersad.com/2012/04/15/do-while-loop-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>★ Random Integers in Python</title>
		<link>http://blog.ryanrampersad.com/2012/04/09/random-integer-python/</link>
		<comments>http://blog.ryanrampersad.com/2012/04/09/random-integer-python/#comments</comments>
		<pubDate>Mon, 09 Apr 2012 17:50:01 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[integer]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://blog.ryanrampersad.com/?p=4859</guid>
		<description><![CDATA[If you need to get a random number in python, and it just needs to be an integer, try importing randint from the random library and then using the inclusive bounds. For instance, if you want numbers between 1 and 6 for a six-sided die, the parameters are simply a &#60;= x &#60;= b, so [...]]]></description>
			<content:encoded><![CDATA[<p>If you need to get a random number in python, and it just needs to be an integer, try importing <code>randint</code> from the random library and then using the inclusive bounds. For instance, if you want numbers between 1 and 6 for a six-sided die, the parameters are simply <code>a &lt;= x &lt;= b</code>, so simply 1 and 6. How intuitive.</p>
<pre class="brush: python; title: ; notranslate">
from random import randint

def get_die():
  die = randint(1,6)
  return die
</pre>
<p>When I learned python years ago, I was scared by the mountain of libraries available.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ryanrampersad.com/2012/04/09/random-integer-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>★ Python: TypeError: can only concatenate list (not &#8220;NoneType&#8221;) to list</title>
		<link>http://blog.ryanrampersad.com/2011/12/01/python-typeerror-can-only-concatenate-list-not-nonetype-to-list/</link>
		<comments>http://blog.ryanrampersad.com/2011/12/01/python-typeerror-can-only-concatenate-list-not-nonetype-to-list/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 17:53:45 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blog.ryanrampersad.com/?p=4570</guid>
		<description><![CDATA[It is pretty unusual for me to be coding in python, but I&#8217;m just following the course in my computer science class. I was coding a recursive list generator, essentially making a list with a given start and ending value of even numbers between them in the list. In my interpreter, I received the following [...]]]></description>
			<content:encoded><![CDATA[<p>It is pretty unusual for me to be coding in python, but I&#8217;m just following the course in my computer science class. I was coding a recursive list generator, essentially making a list with a given start and ending value of even numbers between them in the list.</p>
<p>In my interpreter, I received the following error.</p>
<blockquote>
<pre>
return [start] + list_even(start + 1, end)
TypeError: can only concatenate list
(not "NoneType") to list
</pre>
</blockquote>
<p>I don&#8217;t really know the nature of Python error messages yet, but I think this means that I&#8217;m attempting to something that isn&#8217;t listable (e.g. able to be put into a list). So, something that cannot be added to a list.</p>
<p>My code is pretty simple, though in real life I would never do this recursively.</p>
<pre class="brush: python; title: ; notranslate">
def list_even(start, end):
  if start &gt; end:
    return []
  elif start % 2 == 0:
    return [start] + list_even(start + 1, end)
  else:
    list_even(start + 1, end)
</pre>
<p>Everything looks in order. We have our definition, our if-statement, an else-if branch and a concluding else. Each of those cases have an <code>return</code>. Oh, wait. They don&#8217;t! Notice the <code>else</code> branch does not return a value, instead it just calls itself without returning. That&#8217;s the problem!</p>
<p>So, in short, I missed a <code>return</code> so a <em>NoneType</em> (e.g. null value) was returned during the previous call and it tried to append it on to the list. And clearly appending a null onto a list won&#8217;t work, only appending lists to lists works.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ryanrampersad.com/2011/12/01/python-typeerror-can-only-concatenate-list-not-nonetype-to-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

