Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

directory restructure

  • Loading branch information...
commit 83567d09e05fe341b5e5027bf6770e8a24e177de 0 parents
@stoive authored
Showing with 6,444 additions and 0 deletions.
  1. +75 −0 index.htm
  2. +68 −0 index.xml
  3. +76 −0 lesson01/index.htm
  4. +33 −0 lesson01/index.xml
  5. +33 −0 lesson01/index.xml~
  6. +33 −0 lesson01/newindex.xml~
  7. +236 −0 lesson02/index.htm
  8. +168 −0 lesson02/index.xml
  9. +168 −0 lesson02/index.xml~
  10. +137 −0 lesson03/index.htm
  11. +77 −0 lesson03/index.xml
  12. +77 −0 lesson03/index.xml~
  13. +319 −0 lesson04/index.htm
  14. +236 −0 lesson04/index.xml
  15. +236 −0 lesson04/index.xml~
  16. +419 −0 lesson05/index.htm
  17. +299 −0 lesson05/index.xml
  18. +264 −0 lesson05/index.xml~
  19. +311 −0 lesson06/index.htm
  20. +223 −0 lesson06/index.xml
  21. +223 −0 lesson06/index.xml~
  22. +311 −0 lesson07/index.htm
  23. +241 −0 lesson07/index.xml
  24. +241 −0 lesson07/index.xml~
  25. +250 −0 lesson08/index.htm
  26. +170 −0 lesson08/index.xml
  27. +169 −0 lesson08/index.xml~
  28. +149 −0 lesson09/index.htm
  29. +89 −0 lesson09/index.xml
  30. +67 −0 lesson09/index.xml~
  31. +196 −0 lesson10/index.htm
  32. +132 −0 lesson10/index.xml
  33. +90 −0 lesson10/index.xml~
  34. +268 −0 lesson11/index.htm
  35. +168 −0 lesson11/index.xml
  36. 0  lesson11/index.xml~
  37. +126 −0 lesson12/index.htm
  38. +33 −0 lesson12/index.xml
  39. +33 −0 lesson12/index.xml~
75 index.htm
@@ -0,0 +1,75 @@
+
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
+<meta name="keywords" content="civilization,civ2,civ3,civ4,civilization iii,civilization ii,civilization iv,mod,python,xml,script,install" />
+<meta name="description" content="A Python and XML tutorial aimed at Civilization IV modding" /><!-- put meta tags here -->
+<title>Sthurlow.com - Home</title>
+</head>
+
+<body bgcolor="teal">
+
+<style type="text/CSS">
+
+div.CodeTitle { position: relative; float: center;
+ top:0; width: 90%;
+ background-color:Teal; color: White; }
+
+div.CodeBody { position: relative; overflow: auto; float: center;
+ top:1; width: 90%;
+ background-color:silver; color: black;
+ font-size: 115%; border: 0; }
+
+div.TextPanel { position: relative; top: 15; float: center;
+ background-color: #EAEEFF;
+ border-style: solid; border-color: black; border-width: 1px;
+ font-size: 80%; font-family: Arial,sans-serif; }
+
+div.Padding { position: relative;
+ width: 95%; }
+
+div.PaddingBig { position: relative; align: center;
+ background-color: #EAEEFF;
+ width: 85%; }
+
+table.TableBody { position: relative; overflow: auto; float: center;
+ top:1; width: 90%;
+ background-color:#EAEEFF; color: black;
+ font-size: 110%; border-width: 0; }
+
+td.TableContent { background-color: silver; }
+
+div.ImageCaption { position: relative;
+ top:1;
+ background-color:Teal; color: White; }
+
+div.ImageBody { position: relative;
+ top:0;
+ background-color:silver; color: black; }
+</style>
+
+<div align="center" class="TextPanel">
+<div align="left" class="PaddingBig">
+<h2>A Beginner's Python Tutorial</h2><p>When CivilizationTM IV (Firaxis Games, published by Take2) was announced, one of the most exciting features was that much of the scripting code will be in python, and the game data in XML. This tutorial attempts to teach you the basics of python programming that you could use with civIV.</p>
+ <p>Of course, this tutorial is not limited to those who want to play a slow-paced turn-based strategy game. That is what it was written for, but is perfectly useful to any person with <b>no programming knowledge at all</b>, who wants to learn python. But what makes this tutorial unique, is that it is written for beginners, by a beginner.</p>
+
+ <div align="center"><div align="center" class="CodeTitle">Table 1 - Lessons</div>
+<table class="TableBody">
+ <tr>
+ <td class="TableContent" width="30%"><b>Number</b></td>
+ <td class="TableContent" width="70%"><b>Name</b></td>
+ </tr>
+ <tr>
+ <td class="TableContent" width="%s"><p><a href="./lesson01/">Lesson 1</a><br /></p></td><td class="TableContent" width="%s">Installing Python</td></tr><tr><td class="TableContent" width="%s"><p><a href="./lesson02/">Lesson 2</a><br /></p></td><td class="TableContent" width="%s">Very Simple Programs</td></tr><tr><td class="TableContent" width="%s"><p><a href="./lesson03/">Lesson 3</a><br /></p></td><td class="TableContent" width="%s">Variables, and Programs in a Script</td></tr><tr><td class="TableContent" width="%s"><p><a href="./lesson04/">Lesson 4</a><br /></p></td><td class="TableContent" width="%s">Loops and Conditionals</td></tr><tr><td class="TableContent" width="%s"><p><a href="./lesson05/">Lesson 5</a><br /></p></td><td class="TableContent" width="%s">Functions</td></tr><tr><td class="TableContent" width="%s"><p><a href="./lesson06/">Lesson 6</a><br /></p></td><td class="TableContent" width="%s">Tuples, Lists, and Dictionaries</td></tr><tr><td class="TableContent" width="%s"><p><a href="./lesson07/">Lesson 7</a><br /></p></td><td class="TableContent" width="%s">The for loop</td></tr><tr><td class="TableContent" width="%s"><p><a href="./lesson08/">Lesson 8</a><br /></p></td><td class="TableContent" width="%s">Classes</td></tr><tr><td class="TableContent" width="%s"><p><a href="./lesson09/">Lesson 9</a><br /></p></td><td class="TableContent" width="%s">Importing Modules</td></tr><tr><td class="TableContent" width="%s"><p><a href="./lesson10/">Lesson 10</a><br /></p></td><td class="TableContent" width="%s">File I/O</td></tr><tr><td class="TableContent" width="%s"><p><a href="./lesson11/">Lesson 11</a><br /></p></td><td class="TableContent" width="%s">Error Handling</td></tr></table></div><br /><p>Then we also have the (to be written) Civilization IV python introduction. It will begin its release in early November.</p>
+ <div align="center"><div align="center" class="CodeTitle">Table 2 - Lessons</div>
+<table class="TableBody">
+ <tr>
+ <td class="TableContent" width="30%"><b>Number</b></td>
+ <td class="TableContent" width="70%"><b>Name</b></td>
+ </tr>
+ <tr>
+ <td class="TableContent" width="%s"><p><a href="">Lesson 1</a><br /></p></td><td class="TableContent" width="%s">Introduction to Civilization IV python (not released yet)</td></tr></table></div><br />
+</div></div>
+</body>
+
+</html>
68 index.xml
@@ -0,0 +1,68 @@
+<page>
+ <text>
+ <heading val="2" text="A Beginner's Python Tutorial" />
+ <p>When CivilizationTM IV (Firaxis Games, published by Take2) was announced, one of the most exciting features was that much of the scripting code will be in python, and the game data in XML. This tutorial attempts to teach you the basics of python programming that you could use with civIV.</p>
+ <p>Of course, this tutorial is not limited to those who want to play a slow-paced turn-based strategy game. That is what it was written for, but is perfectly useful to any person with &lt;b&gt;no programming knowledge at all&lt;/b&gt;, who wants to learn python. But what makes this tutorial unique, is that it is written for beginners, by a beginner.</p>
+ </text>
+ <table title="Lessons">
+ <row>
+ <column title="Number" width="30%"/>
+ <column title="Name" width="70%"/>
+ </row>
+ <row>
+ <cell><link text="Lesson 1" dest ="./lesson01/" /></cell>
+ <cell>Installing Python</cell>
+ </row>
+ <row>
+ <cell><link text="Lesson 2" dest ="./lesson02/" /></cell>
+ <cell>Very Simple Programs</cell>
+ </row>
+ <row>
+ <cell><link text="Lesson 3" dest ="./lesson03/" /></cell>
+ <cell>Variables, and Programs in a Script</cell>
+ </row>
+ <row>
+ <cell><link text="Lesson 4" dest ="./lesson04/" /></cell>
+ <cell>Loops and Conditionals</cell>
+ </row>
+ <row>
+ <cell><link text="Lesson 5" dest ="./lesson05/" /></cell>
+ <cell>Functions</cell>
+ </row>
+ <row>
+ <cell><link text="Lesson 6" dest ="./lesson06/" /></cell>
+ <cell>Tuples, Lists, and Dictionaries</cell>
+ </row>
+ <row>
+ <cell><link text="Lesson 7" dest ="./lesson07/" /></cell>
+ <cell>The for loop</cell>
+ </row>
+ <row>
+ <cell><link text="Lesson 8" dest ="./lesson08/" /></cell>
+ <cell>Classes</cell>
+ </row>
+ <row>
+ <cell><link text="Lesson 9" dest ="./lesson09/" /></cell>
+ <cell>Importing Modules</cell>
+ </row>
+ <row>
+ <cell><link text="Lesson 10" dest ="./lesson10/" /></cell>
+ <cell>File I/O</cell>
+ </row>
+ <row>
+ <cell><link text="Lesson 11" dest ="./lesson11/" /></cell>
+ <cell>Error Handling</cell>
+ </row>
+ </table>
+ <p>Then we also have the (to be written) Civilization IV python introduction. It will begin its release in early November.</p>
+ <table title="Lessons">
+ <row>
+ <column title="Number" width="30%"/>
+ <column title="Name" width="70%"/>
+ </row>
+ <row>
+ <cell><link text="Lesson 1" dest ="" /></cell>
+ <cell>Introduction to Civilization IV python (not released yet)</cell>
+ </row>
+ </table>
+</page>
76 lesson01/index.htm
@@ -0,0 +1,76 @@
+<html>
+<head>
+<title>Lesson 1 - Installing Python</title>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
+<meta name="keywords" content="civilization,civ2,civ3,civ4,civilization iii,civilization ii,civilization iv,mod,python,xml,script,install" />
+<meta name="description" content="A Python and XML tutorial aimed at Civilization IV modding" />
+</head><link rel="stylesheet" type="text/css" href="../../stylesheet.css" />
+
+<body bgcolor="Teal">
+<div align="center" class="SidePanel">
+<div align="left" class="PaddingBig">
+<div class="MenuSection">
+<h1>Sthurlow.com</h1>
+<h2>Civilization IV Python tutorial</h2><h3>The Python Tutorial</h3>
+<p>The original sthurlow.com python tutorial</p>
+<p>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson01/">Installing Python</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson02/">Very Simple Programs</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson03/">Variables, Scripts</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson04/">Loops, Conditionals</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson05/">Functions</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson06/">Tuples, Lists, Dictionaries</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson07/">for Loop</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson08/">Classes</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson09/">Importing Modules</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson10/">File I/O</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson11/">Error Handling</a></div>
+</p>
+<h3>The Civ4 Programming Tutorial</h3>
+<p>All new Civ4 programming tutorial</p>
+<p>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/">Lesson 1 (not released)</a></div>
+</p>
+<br /><br /></div></div>
+</div>
+
+<div align="center" class="TextPanel">
+<div align="left" class="Padding"><h2>Installing Python</h2>
+
+<h3>What is python?</h3>
+<p>If you don't understand this, don't worry. Just skip it and move on.</p>
+<p>Python is an <b>interpreted</b> <i>programming language</i>. For those who don't know, a programming language is what you write down to tell a computer what to do. However, the computer doesn't read the language directly - there are hundreds of programming languages, and it couldn't understand them all. So, when someone writes a program, they will write it in their language of choice, and then compile it - that is, turn it in to lots of 0s and 1s, that the computer can easily and quickly understand. A windows program that you buy is already compiled for windows - if you opened the program file up, you'd just get a mass of weird characters and rectangles. Give it a go - find a small windows program, and open it up in notepad or wordpad. See what garbled mess you get.</p>
+<p>But that windows program is compiled for windows - no other machine can run that program, unless it has windows. What Python is, is a language which is never actually compiled in full - instead, an interpreter turns each line of code into 0s and 1s that your computer can understand this. And it is done on the fly - it compiles the bits of the program you are using as you are using them. If you were to quit the program and come back another day, it would compile the bits you are using, as you are using them, again. Seems a waste of time? Maybe, but the fact is that when you come back another day, you might be using a Windows instead of a Mac. You might send the program to a friend, who uses another type of computer. Or you might post your program on the internet, where everyone using all different types of systems might download it. That is the wonder of an interpreted programming language - it is like a language that EVERYONE can understand.</p>
+
+<h3>So why will civIV use Python?</h3>
+
+<div align="center" class="ImageBody" style="float: right;">
+<img src="../../images/01_garble.jpg" />
+<div align="center" class="ImageCaption">Image 1 - The garbled mess of a compiled program</div></div>
+<p>Remember that garbled mess that you got when opening a program in notepad? Not much use to anyone, apart from the computer. And there is no reliable (or legal) way of turning that program back in to a programming language that you or I could understand.</p>
+<p>The same is with Civ3 AI - it is compiled into a garbled mess. Nobody can understand it, and most of all, nobody can change it. Only Firaxis can change the AI, and they can't share the logic behind it with anyone.</p>
+<p>With cIV, they decided to change that - they would leave the AI uncompiled in the language of Python, and have it compiled on-the-fly by an interpreter. This is so that Joe modder can look at the AI and change it, yet when it is neede to be used, the python interpreter turns it into 0s and 1s for your computer to understand. And it isn't permanently compiled into a garbled mess - you are still left with python code, that you can read, understand, and MODIFY!!!!!</p>
+
+<h3>How to install python</h3>
+<ol>
+<li>First download <a href="http://www.python.org/ftp/python/2.4.1/python-2.4.1.msi">Python-2.4.1.exe</a> by following this link. If you are a dialup user, keep in mind that the file is around 10MB</li>
+<li>Run the file you just downloaded, and follow the prompts.</li>
+</ol>
+<p>OK! Hopefully now everything is good! Now, to test if that just worked, type this in your DOS window:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 1 - Testing the installation</div>
+<div align="left" class="CodeBody">
+<pre>
+python -V
+</pre>
+</div>
+</div><p>If you forgot a CAPITAL V, you will accidently load python in verbose mode. Give it a go, see what happens. Just press CTRL-D to quit, or type 'quit' for quit instructions.</p>
+
+<h3>conclusion</h3>
+<p>Good work! Lesson 1 over! Next lesson, we learn our way around Python Interactive Mode, and write simple one-line pieces of code. I'll also have a lesson plan drawn up by then, so you can see where you are going. If any of our more experienced members have suggestions for the lesson plan, tell me!</p>
+<p>Thanks to all,</p>
+<p>sthurlow.com</p>
+
+</div></div></body>
+</html>
33 lesson01/index.xml
@@ -0,0 +1,33 @@
+<document>
+<lesson number="1" title="Installing Python" author="Steven Thurlow" style="../../stylesheet.css">
+ <content>
+ <section title="What is python?">
+ <p>If you don't understand this, don't worry. Just skip it and move on.</p>
+ <p>Python is an <b>interpreted</b> <i>programming language</i>. For those who don't know, a programming language is what you write down to tell a computer what to do. However, the computer doesn't read the language directly - there are hundreds of programming languages, and it couldn't understand them all. So, when someone writes a program, they will write it in their language of choice, and then compile it - that is, turn it in to lots of 0s and 1s, that the computer can easily and quickly understand. A windows program that you buy is already compiled for windows - if you opened the program file up, you'd just get a mass of weird characters and rectangles. Give it a go - find a small windows program, and open it up in notepad or wordpad. See what garbled mess you get.</p>
+ <p>But that windows program is compiled for windows - no other machine can run that program, unless it has windows. What Python is, is a language which is never actually compiled in full - instead, an interpreter turns each line of code into 0s and 1s that your computer can understand this. And it is done on the fly - it compiles the bits of the program you are using as you are using them. If you were to quit the program and come back another day, it would compile the bits you are using, as you are using them, again. Seems a waste of time? Maybe, but the fact is that when you come back another day, you might be using a Windows instead of a Mac. You might send the program to a friend, who uses another type of computer. Or you might post your program on the internet, where everyone using all different types of systems might download it. That is the wonder of an interpreted programming language - it is like a language that EVERYONE can understand.</p>
+ </section>
+ <section title="So why will civIV use Python?">
+ <image align="right" location="../../images/01_garble.jpg" caption="The garbled mess of a compiled program" />
+ <p>Remember that garbled mess that you got when opening a program in notepad? Not much use to anyone, apart from the computer. And there is no reliable (or legal) way of turning that program back in to a programming language that you or I could understand.</p>
+ <p>The same is with Civ3 AI - it is compiled into a garbled mess. Nobody can understand it, and most of all, nobody can change it. Only Firaxis can change the AI, and they can't share the logic behind it with anyone.</p>
+ <p>With cIV, they decided to change that - they would leave the AI uncompiled in the language of Python, and have it compiled on-the-fly by an interpreter. This is so that Joe modder can look at the AI and change it, yet when it is neede to be used, the python interpreter turns it into 0s and 1s for your computer to understand. And it isn't permanently compiled into a garbled mess - you are still left with python code, that you can read, understand, and MODIFY!!!!!</p>
+ </section>
+ <section title="How to install python">
+ <orderedList>
+ <entry>First download <link location="http://www.python.org/ftp/python/2.4.1/python-2.4.1.msi">Python-2.4.1.exe</link> by following this link. If you are a dialup user, keep in mind that the file is around 10MB</entry>
+ <entry>Run the file you just downloaded, and follow the prompts.</entry>
+ </orderedList>
+ <p>OK! Hopefully now everything is good! Now, to test if that just worked, type this in your DOS window:</p>
+ <code title="Testing the installation">
+ <l>python -V</l>
+ </code>
+ <p>If you forgot a CAPITAL V, you will accidently load python in verbose mode. Give it a go, see what happens. Just press CTRL-D to quit, or type 'quit' for quit instructions.</p>
+ </section>
+ <section title="conclusion">
+ <p>Good work! Lesson 1 over! Next lesson, we learn our way around Python Interactive Mode, and write simple one-line pieces of code. I'll also have a lesson plan drawn up by then, so you can see where you are going. If any of our more experienced members have suggestions for the lesson plan, tell me!</p>
+ <p>Thanks to all,</p>
+ <p>sthurlow.com</p>
+ </section>
+ </content>
+</lesson>
+</document>
33 lesson01/index.xml~
@@ -0,0 +1,33 @@
+<tutorial>
+<lesson number="1" title="Installing Python" author="Steven Thurlow">
+ <content>
+ <section title="What is python?">
+ <p>If you don't understand this, don't worry. Just skip it and move on.</p>
+ <p>Python is an &lt;b&gt;interpreted&lt;/b&gt; &lt;i&gt;programming language&lt;/i&gt;. For those who don't know, a programming language is what you write down to tell a computer what to do. However, the computer doesn't read the language directly - there are hundreds of programming languages, and it couldn't understand them all. So, when someone writes a program, they will write it in their language of choice, and then compile it - that is, turn it in to lots of 0s and 1s, that the computer can easily and quickly understand. A windows program that you buy is already compiled for windows - if you opened the program file up, you'd just get a mass of weird characters and rectangles. Give it a go - find a small windows program, and open it up in notepad or wordpad. See what garbled mess you get.</p>
+ <p>But that windows program is compiled for windows - no other machine can run that program, unless it has windows. What Python is, is a language which is never actually compiled in full - instead, an interpreter turns each line of code into 0s and 1s that your computer can understand this. And it is done on the fly - it compiles the bits of the program you are using as you are using them. If you were to quit the program and come back another day, it would compile the bits you are using, as you are using them, again. Seems a waste of time? Maybe, but the fact is that when you come back another day, you might be using a Windows instead of a Mac. You might send the program to a friend, who uses another type of computer. Or you might post your program on the internet, where everyone using all different types of systems might download it. That is the wonder of an interpreted programming language - it is like a language that EVERYONE can understand.</p>
+ </section>
+ <section title="So why will civIV use Python?">
+ <image align="right" location="../../images/01_garble.jpg" caption="The garbled mess of a compiled program" />
+ <p>Remember that garbled mess that you got when opening a program in notepad? Not much use to anyone, apart from the computer. And there is no reliable (or legal) way of turning that program back in to a programming language that you or I could understand.</p>
+ <p>The same is with Civ3 AI - it is compiled into a garbled mess. Nobody can understand it, and most of all, nobody can change it. Only Firaxis can change the AI, and they can't share the logic behind it with anyone.</p>
+ <p>With cIV, they decided to change that - they would leave the AI uncompiled in the language of Python, and have it compiled on-the-fly by an interpreter. This is so that Joe modder can look at the AI and change it, yet when it is neede to be used, the python interpreter turns it into 0s and 1s for your computer to understand. And it isn't permanently compiled into a garbled mess - you are still left with python code, that you can read, understand, and MODIFY!!!!!</p>
+ </section>
+ <section title="How to install python">
+ <list state="ordered">
+ <entry>First download <link dest="http://www.python.org/ftp/python/2.4.1/python-2.4.1.msi" text="Python-2.4.1.exe" /> by following this link. If you are a dialup user, keep in mind that the file is around 10MB</entry>
+ <entry>Run the file you just downloaded, and follow the prompts.</entry>
+ </list>
+ <p>OK! Hopefully now everything is good! Now, to test if that just worked, type this in your DOS window:</p>
+ <code title="Testing the installation">
+ <l>python -V</l>
+ </code>
+ <p>If you forgot a CAPITAL V, you will accidently load python in verbose mode. Give it a go, see what happens. Just press CTRL-D to quit, or type 'quit' for quit instructions.</p>
+ </section>
+ <section title="conclusion">
+ <p>Good work! Lesson 1 over! Next lesson, we learn our way around Python Interactive Mode, and write simple one-line pieces of code. I'll also have a lesson plan drawn up by then, so you can see where you are going. If any of our more experienced members have suggestions for the lesson plan, tell me!</p>
+ <p>Thanks to all,</p>
+ <p>sthurlow.com</p>
+ </section>
+ </content>
+</lesson>
+</tutorial>
33 lesson01/newindex.xml~
@@ -0,0 +1,33 @@
+<document>
+<lesson number="1" title="Installing Python" author="Steven Thurlow" style="../../stylesheet.css">
+ <content>
+ <section title="What is python?">
+ <p>If you don't understand this, don't worry. Just skip it and move on.</p>
+ <p>Python is an &lt;b&gt;interpreted&lt;/b&gt; &lt;i&gt;programming language&lt;/i&gt;. For those who don't know, a programming language is what you write down to tell a computer what to do. However, the computer doesn't read the language directly - there are hundreds of programming languages, and it couldn't understand them all. So, when someone writes a program, they will write it in their language of choice, and then compile it - that is, turn it in to lots of 0s and 1s, that the computer can easily and quickly understand. A windows program that you buy is already compiled for windows - if you opened the program file up, you'd just get a mass of weird characters and rectangles. Give it a go - find a small windows program, and open it up in notepad or wordpad. See what garbled mess you get.</p>
+ <p>But that windows program is compiled for windows - no other machine can run that program, unless it has windows. What Python is, is a language which is never actually compiled in full - instead, an interpreter turns each line of code into 0s and 1s that your computer can understand this. And it is done on the fly - it compiles the bits of the program you are using as you are using them. If you were to quit the program and come back another day, it would compile the bits you are using, as you are using them, again. Seems a waste of time? Maybe, but the fact is that when you come back another day, you might be using a Windows instead of a Mac. You might send the program to a friend, who uses another type of computer. Or you might post your program on the internet, where everyone using all different types of systems might download it. That is the wonder of an interpreted programming language - it is like a language that EVERYONE can understand.</p>
+ </section>
+ <section title="So why will civIV use Python?">
+ <image align="right" location="../../images/01_garble.jpg" caption="The garbled mess of a compiled program" />
+ <p>Remember that garbled mess that you got when opening a program in notepad? Not much use to anyone, apart from the computer. And there is no reliable (or legal) way of turning that program back in to a programming language that you or I could understand.</p>
+ <p>The same is with Civ3 AI - it is compiled into a garbled mess. Nobody can understand it, and most of all, nobody can change it. Only Firaxis can change the AI, and they can't share the logic behind it with anyone.</p>
+ <p>With cIV, they decided to change that - they would leave the AI uncompiled in the language of Python, and have it compiled on-the-fly by an interpreter. This is so that Joe modder can look at the AI and change it, yet when it is neede to be used, the python interpreter turns it into 0s and 1s for your computer to understand. And it isn't permanently compiled into a garbled mess - you are still left with python code, that you can read, understand, and MODIFY!!!!!</p>
+ </section>
+ <section title="How to install python">
+ <orderedList>
+ <entry>First download <link location="http://www.python.org/ftp/python/2.4.1/python-2.4.1.msi">Python-2.4.1.exe</link> by following this link. If you are a dialup user, keep in mind that the file is around 10MB</entry>
+ <entry>Run the file you just downloaded, and follow the prompts.</entry>
+ </orderedList>
+ <p>OK! Hopefully now everything is good! Now, to test if that just worked, type this in your DOS window:</p>
+ <code title="Testing the installation">
+ <l>python -V</l>
+ </code>
+ <p>If you forgot a CAPITAL V, you will accidently load python in verbose mode. Give it a go, see what happens. Just press CTRL-D to quit, or type 'quit' for quit instructions.</p>
+ </section>
+ <section title="conclusion">
+ <p>Good work! Lesson 1 over! Next lesson, we learn our way around Python Interactive Mode, and write simple one-line pieces of code. I'll also have a lesson plan drawn up by then, so you can see where you are going. If any of our more experienced members have suggestions for the lesson plan, tell me!</p>
+ <p>Thanks to all,</p>
+ <p>sthurlow.com</p>
+ </section>
+ </content>
+</lesson>
+</document>
236 lesson02/index.htm
@@ -0,0 +1,236 @@
+<html>
+<head>
+<title>Lesson 2 - Very simple 'programs'</title>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
+<meta name="keywords" content="civilization,civ2,civ3,civ4,civilization iii,civilization ii,civilization iv,mod,python,xml,script,install" />
+<meta name="description" content="A Python and XML tutorial aimed at Civilization IV modding" />
+</head><link rel="stylesheet" type="text/css" href="../../stylesheet.css" />
+
+<body bgcolor="Teal">
+<div align="center" class="SidePanel">
+<div align="left" class="PaddingBig">
+<div class="MenuSection">
+<h1>Sthurlow.com</h1>
+<h2>Civilization IV Python tutorial</h2><h3>The Python Tutorial</h3>
+<p>The original sthurlow.com python tutorial</p>
+<p>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson01/">Installing Python</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson02/">Very Simple Programs</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson03/">Variables, Scripts</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson04/">Loops, Conditionals</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson05/">Functions</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson06/">Tuples, Lists, Dictionaries</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson07/">for Loop</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson08/">Classes</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson09/">Importing Modules</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson10/">File I/O</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson11/">Error Handling</a></div>
+</p>
+<h3>The Civ4 Programming Tutorial</h3>
+<p>All new Civ4 programming tutorial</p>
+<p>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/">Lesson 1 (not released)</a></div>
+</p>
+<br /><br /></div></div>
+</div>
+
+<div align="center" class="TextPanel">
+<div align="left" class="Padding"><h2>Very simple 'programs'</h2>
+
+<h3>Introduction</h3>
+<p>OK! We have python installed, now what? Well, we program!</p>
+<p>And it is that simple (at least for now). Python makes it easy to run single lines of code - one-liner programs. Lets give it a go.</p>
+
+<h3>Opening IDLE</h3>
+<p>Go to the start menu, find Python, and run the program labelled 'IDLE' (Stands for Integrated Development Environment.</p>
+<p>Now you are in the IDLE environment. This is the place you will be spending most time in. Here you can open a new window to write a program, or you can simply mess around with single lines of code, which is what we are going to do. Type the following and press enter: (don't type >>> as it should already be there)</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 1 - Hello, World!</div>
+<div align="left" class="CodeBody">
+<pre>
+>>> print "Hello, World!"
+</pre>
+</div>
+</div><p>What happened? You just created a program, that prints the words 'Hello, World'. The IDLE environment that you are in immediately compiles whatever you have typed in. This is useful for testing things, e.g. define a few variables, and then test to see if a certain line will work. That will come in a later lesson, though.</p>
+
+<h3>Math in Python</h3>
+<p>Now try typing the stuff in bold. You should get the output shown in blue. I've given explainations in brackets.</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 2 - Maths</div>
+<div align="left" class="CodeBody">
+<pre>
+>>> 1 + 1
+2
+
+>>> 20+80
+100
+>>> 18294+449566
+467860
+(These are additions)
+>>> 6-5
+1
+(Subtraction)
+>>> 2*5
+10
+(Multiply, rabbits!)
+>>> 5**2
+25
+(Exponentials e.g. this one is 5 squared)
+
+>>> print "1 + 2 is an addition"
+1 + 2 is an addition
+(the print statement, which writes something onscreen)
+>>> print "one kilobyte is 2^10 bytes, or", 2**10, "bytes"
+one kilobyte is 2^10 bytes, or 1024 bytes
+(you can print sums and variables in a sentence.
+ The commas seperating each section are a way of
+ seperating clearly different things that you are printing)
+
+>>> 21/3
+7
+>>> 23/3
+7
+>>> 23.0/3.0
+7.6666...
+(division, 2nd time ignoring remainder/decimals,
+ 3rd time including decimals)
+>>> 23%3
+2
+>>> 49%10
+9
+(the remainder from a division)
+</pre>
+</div>
+</div><p>As you see, there is the code, then the result of that code. I then explain them in brackets. These are the basic commands of python, and what they do. Here is a table to clarify them (because tables look cool, and make you feel smarter ;) ):</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Table 1 - Python operators</div>
+<table class="TableBody">
+<tr>
+<td class="TableContent" width="25%"><b>command</b></td>
+<td class="TableContent" width="25%"><b>name</b></td>
+<td class="TableContent" width="25%"><b>example</b></td>
+<td class="TableContent" width="25%"><b>output</b></td>
+</tr>
+<tr>
+<td class="TableContent">+</td>
+<td class="TableContent">Addition</td>
+<td class="TableContent">4+5</td>
+<td class="TableContent">9</td>
+</tr>
+<tr>
+<td class="TableContent">-</td>
+<td class="TableContent">Subtraction</td>
+<td class="TableContent">8-5</td>
+<td class="TableContent">3</td>
+</tr>
+<tr>
+<td class="TableContent">*</td>
+<td class="TableContent">Multiplication</td>
+<td class="TableContent">4*5</td>
+<td class="TableContent">20</td>
+</tr>
+<tr>
+<td class="TableContent">/</td>
+<td class="TableContent">Division</td>
+<td class="TableContent">19/3</td>
+<td class="TableContent">6</td>
+</tr>
+<tr>
+<td class="TableContent">%</td>
+<td class="TableContent">Remainder</td>
+<td class="TableContent">19%3</td>
+<td class="TableContent">5</td>
+</tr>
+<tr>
+<td class="TableContent">**</td>
+<td class="TableContent">Exponent</td>
+<td class="TableContent">2**4</td>
+<td class="TableContent">16</td>
+</tr>
+</table>
+</div><br /><p>Remember that thing called order of operation that they taught in maths? Well, it applies in python, too. Here it is, if you need reminding:</p>
+<ol>
+<li>parentheses ()</li>
+<li>exponents **</li>
+<li>multiplication *, division \, and remainder %</li>
+<li>addition + and subtraction -</li>
+</ol>
+
+<h3>Order of Operations</h3>
+<p>Here are some examples that you might want to try, if you're rusty on this:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 3 - Order of Operations</div>
+<div align="left" class="CodeBody">
+<pre>
+>>> 1 + 2 * 3
+7
+>>> (1 + 2) * 3
+9
+</pre>
+</div>
+</div><p>In the first example, the computer calculates 2 * 3 first, then adds 1 to it. This is because multiplication has the higher priority (at 3) and addition is below that (at lowly 4).</p>
+<p>In the second example, the computer calculates 1 + 2 first, then multiplies it by 3. This is because parentheses (brackets, like the ones that are surrounding this interluding text ;) ) have the higher priority (at 1) and addition comes in later than that.</p>
+<p>Also remember that the math is calculated from left to right, UNLESS you put in parentheses. The innermost parentheses are calculated first. Watch these examples:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 4 - Parentheses</div>
+<div align="left" class="CodeBody">
+<pre>
+>>> 4 - 40 - 3
+-39
+>>> 4 - (40 - 3)
+-33
+</pre>
+</div>
+</div><p>In the first example, 4 -40 is calculated,then - 3 is done.</p>
+<p>In the second example, 40 - 3 is calculated, then it is subtracted from 4.</p>
+
+<h3>Comments, Please</h3>
+<p>The final thing you'll need to know to move on to multi-line programs is the comment. Type the following (and yes, the output is shown):</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 5 - comments</div>
+<div align="left" class="CodeBody">
+<pre>
+>>> #I am a comment. Fear my wrath!
+
+>>>
+</pre>
+</div>
+</div><p>A comment is a piece of code that is not run. In python, you make something a comment by putting a hash in front of it. A hash comments everything after it in the line, and nothing before it. So you could type this:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 6 - comment examples</div>
+<div align="left" class="CodeBody">
+<pre>
+>>> print "food is very nice" #eat me
+
+food is very nice
+
+(a normal output, without the smutty comment,
+thankyou very much)
+
+>>># print "food is very nice"
+
+(nothing happens, because the code was after a comment)
+
+>>> print "food is very nice" eat me
+
+(you'll get a fairly harmless error message,
+because you didn't put your comment after a hash)
+</pre>
+</div>
+</div><p>Comments are important for adding necessary information for another programmer to read, but not the computer. For example, an explanation of a section of code, saying what it does, or what is wrong with it. You can also comment bits of code by putting a # in front of it - if you don't want it to compile, but cant delete it because you might need it later.</p>
+
+<h3>Conclusion</h3>
+<p>There you go! Lesson 2 Completed. That was even shorter than lesson 1!</p>
+<p>Next lesson, we make programs with many lines of code, and save them, so we can actually send them to people. That's right, you don't have to retype every program you run! What an amazing innovation!</p>
+<p>Thanks to all,</p>
+<p>sthurlow.com</p>
+
+</div></div></body>
+</html>
168 lesson02/index.xml
@@ -0,0 +1,168 @@
+<document>
+<lesson number="2" title="Very simple 'programs'" author="Steven Thurlow" style="../../stylesheet.css">
+ <content>
+ <section title="Introduction">
+ <p>OK! We have python installed, now what? Well, we program!</p>
+ <p>And it is that simple (at least for now). Python makes it easy to run single lines of code - one-liner programs. Lets give it a go.</p>
+ </section>
+ <section title="Opening IDLE">
+ <p>Go to the start menu, find Python, and run the program labelled 'IDLE' (Stands for Integrated Development Environment.</p>
+ <p>Now you are in the IDLE environment. This is the place you will be spending most time in. Here you can open a new window to write a program, or you can simply mess around with single lines of code, which is what we are going to do. Type the following and press enter: (don't type >>> as it should already be there)</p>
+ <code title="Hello, World!">
+ <l>&gt;&gt;&gt; print "Hello, World!"</l>
+ </code>
+ <p>What happened? You just created a program, that prints the words 'Hello, World'. The IDLE environment that you are in immediately compiles whatever you have typed in. This is useful for testing things, e.g. define a few variables, and then test to see if a certain line will work. That will come in a later lesson, though.</p>
+ </section>
+ <section title="Math in Python">
+ <p>Now try typing the stuff in bold. You should get the output shown in blue. I've given explainations in brackets.</p>
+ <code title="Maths">
+ <l>&gt;&gt;&gt; 1 + 1</l>
+ <l>2</l>
+ <l></l>
+ <l>&gt;&gt;&gt; 20+80</l>
+ <l>100</l>
+ <l>&gt;&gt;&gt; 18294+449566</l>
+ <l>467860</l>
+ <l>(These are additions)</l>
+ <l>&gt;&gt;&gt; 6-5</l>
+ <l>1</l>
+ <l>(Subtraction)</l>
+ <l>&gt;&gt;&gt; 2*5</l>
+ <l>10</l>
+ <l>(Multiply, rabbits!)</l>
+ <l>&gt;&gt;&gt; 5**2</l>
+ <l>25</l>
+ <l>(Exponentials e.g. this one is 5 squared)</l>
+ <l></l>
+ <l>&gt;&gt;&gt; print "1 + 2 is an addition"</l>
+ <l>1 + 2 is an addition</l>
+ <l>(the print statement, which writes something onscreen)</l>
+ <l>&gt;&gt;&gt; print "one kilobyte is 2^10 bytes, or", 2**10, "bytes"</l>
+ <l>one kilobyte is 2^10 bytes, or 1024 bytes</l>
+ <l>(you can print sums and variables in a sentence.</l>
+ <l> The commas seperating each section are a way of</l>
+ <l> seperating clearly different things that you are printing)</l>
+ <l></l>
+ <l>&gt;&gt;&gt; 21/3</l>
+ <l>7</l>
+ <l>&gt;&gt;&gt; 23/3</l>
+ <l>7</l>
+ <l>&gt;&gt;&gt; 23.0/3.0</l>
+ <l>7.6666...</l>
+ <l>(division, 2nd time ignoring remainder/decimals,</l>
+ <l> 3rd time including decimals)</l>
+ <l>&gt;&gt;&gt; 23%3</l>
+ <l>2</l>
+ <l>&gt;&gt;&gt; 49%10</l>
+ <l>9</l>
+ <l>(the remainder from a division)</l>
+ </code>
+ <p>As you see, there is the code, then the result of that code. I then explain them in brackets. These are the basic commands of python, and what they do. Here is a table to clarify them (because tables look cool, and make you feel smarter ;) ):</p>
+ <table title="Python operators">
+ <row>
+ <column title="command" width="25%" />
+ <column title="name" width="25%" />
+ <column title="example" width="25%" />
+ <column title="output" width="25%" />
+ </row>
+ <row>
+ <cell>+</cell>
+ <cell>Addition</cell>
+ <cell>4+5</cell>
+ <cell>9</cell>
+ </row>
+ <row>
+ <cell>-</cell>
+ <cell>Subtraction</cell>
+ <cell>8-5</cell>
+ <cell>3</cell>
+ </row>
+ <row>
+ <cell>*</cell>
+ <cell>Multiplication</cell>
+ <cell>4*5</cell>
+ <cell>20</cell>
+ </row>
+ <row>
+ <cell>/</cell>
+ <cell>Division</cell>
+ <cell>19/3</cell>
+ <cell>6</cell>
+ </row>
+ <row>
+ <cell>&#37;</cell>
+ <cell>Remainder</cell>
+ <cell>19&#37;3</cell>
+ <cell>5</cell>
+ </row>
+ <row>
+ <cell>**</cell>
+ <cell>Exponent</cell>
+ <cell>2**4</cell>
+ <cell>16</cell>
+ </row>
+ </table>
+ <p>Remember that thing called order of operation that they taught in maths? Well, it applies in python, too. Here it is, if you need reminding:</p>
+ <orderedList>
+ <entry>parentheses ()</entry>
+ <entry>exponents **</entry>
+ <entry>multiplication *, division \, and remainder %</entry>
+ <entry>addition + and subtraction -</entry>
+ </orderedList>
+ </section>
+ <section title="Order of Operations">
+ <p>Here are some examples that you might want to try, if you're rusty on this:</p>
+ <code title="Order of Operations">
+ <l>&gt;&gt;&gt; 1 + 2 * 3</l>
+ <l>7</l>
+ <l>&gt;&gt;&gt; (1 + 2) * 3</l>
+ <l>9</l>
+ </code>
+ <p>In the first example, the computer calculates 2 * 3 first, then adds 1 to it. This is because multiplication has the higher priority (at 3) and addition is below that (at lowly 4).</p>
+ <p>In the second example, the computer calculates 1 + 2 first, then multiplies it by 3. This is because parentheses (brackets, like the ones that are surrounding this interluding text ;) ) have the higher priority (at 1) and addition comes in later than that.</p>
+ <p>Also remember that the math is calculated from left to right, UNLESS you put in parentheses. The innermost parentheses are calculated first. Watch these examples:</p>
+ <code title="Parentheses">
+ <l>&gt;&gt;&gt; 4 - 40 - 3</l>
+ <l>-39</l>
+ <l>&gt;&gt;&gt; 4 - (40 - 3)</l>
+ <l>-33</l>
+ </code>
+ <p>In the first example, 4 -40 is calculated,then - 3 is done.</p>
+ <p>In the second example, 40 - 3 is calculated, then it is subtracted from 4.</p>
+ </section>
+ <section title="Comments, Please">
+ <p>The final thing you'll need to know to move on to multi-line programs is the comment. Type the following (and yes, the output is shown):</p>
+ <code title="comments">
+ <l>&gt;&gt;&gt; #I am a comment. Fear my wrath!</l>
+ <l></l>
+ <l>&gt;&gt;&gt;</l>
+ </code>
+ <p>A comment is a piece of code that is not run. In python, you make something a comment by putting a hash in front of it. A hash comments everything after it in the line, and nothing before it. So you could type this:</p>
+ <code title="comment examples">
+ <l>&gt;&gt;&gt; print "food is very nice" #eat me</l>
+ <l></l>
+ <l>food is very nice</l>
+ <l></l>
+ <l>(a normal output, without the smutty comment,</l>
+ <l>thankyou very much)</l>
+ <l></l>
+ <l>&gt;&gt;&gt;# print "food is very nice"</l>
+ <l></l>
+ <l>(nothing happens, because the code was after a comment)</l>
+ <l></l>
+ <l>&gt;&gt;&gt; print "food is very nice" eat me</l>
+ <l></l>
+ <l>(you'll get a fairly harmless error message,</l>
+ <l>because you didn't put your comment after a hash)</l>
+ </code>
+ <p>Comments are important for adding necessary information for another programmer to read, but not the computer. For example, an explanation of a section of code, saying what it does, or what is wrong with it. You can also comment bits of code by putting a # in front of it - if you don't want it to compile, but cant delete it because you might need it later.</p>
+ </section>
+ <section title="Conclusion">
+ <p>There you go! Lesson 2 Completed. That was even shorter than lesson 1!</p>
+ <p>Next lesson, we make programs with many lines of code, and save them, so we can actually send them to people. That's right, you don't have to retype every program you run! What an amazing innovation!</p>
+ <p>Thanks to all,</p>
+ <p>sthurlow.com</p>
+ </section>
+ </content>
+</lesson>
+</document>
168 lesson02/index.xml~
@@ -0,0 +1,168 @@
+<document>
+<lesson number="2" title="Very simple 'programs'" author="Steven Thurlow" style="../../stylesheet.css">
+ <content>
+ <section title="Introduction">
+ <p>OK! We have python installed, now what? Well, we program!</p>
+ <p>And it is that simple (at least for now). Python makes it easy to run single lines of code - one-liner programs. Lets give it a go.</p>
+ </section>
+ <section title="Opening IDLE">
+ <p>Go to the start menu, find Python, and run the program labelled 'IDLE' (Stands for Integrated Development Environment.</p>
+ <p>Now you are in the IDLE environment. This is the place you will be spending most time in. Here you can open a new window to write a program, or you can simply mess around with single lines of code, which is what we are going to do. Type the following and press enter: (don't type >>> as it should already be there)</p>
+ <code title="Hello, World!">
+ <l>&gt;&gt;&gt; print "Hello, World!"</l>
+ </code>
+ <p>What happened? You just created a program, that prints the words 'Hello, World'. The IDLE environment that you are in immediately compiles whatever you have typed in. This is useful for testing things, e.g. define a few variables, and then test to see if a certain line will work. That will come in a later lesson, though.</p>
+ </section>
+ <section title="Math in Python">
+ <p>Now try typing the stuff in bold. You should get the output shown in blue. I've given explainations in brackets.</p>
+ <code title="Maths">
+ <l>&gt;&gt;&gt; 1 + 1</l>
+ <l>2</l>
+ <l></l>
+ <l>&gt;&gt;&gt; 20+80</l>
+ <l>100</l>
+ <l>&gt;&gt;&gt; 18294+449566</l>
+ <l>467860</l>
+ <l>(These are additions)</l>
+ <l>&gt;&gt;&gt; 6-5</l>
+ <l>1</l>
+ <l>(Subtraction)</l>
+ <l>&gt;&gt;&gt; 2*5</l>
+ <l>10</l>
+ <l>(Multiply, rabbits!)</l>
+ <l>&gt;&gt;&gt; 5**2</l>
+ <l>25</l>
+ <l>(Exponentials e.g. this one is 5 squared)</l>
+ <l></l>
+ <l>&gt;&gt;&gt; print "1 + 2 is an addition"</l>
+ <l>1 + 2 is an addition</l>
+ <l>(the print statement, which writes something onscreen)</l>
+ <l>&gt;&gt;&gt; print "one kilobyte is 2^10 bytes, or", 2**10, "bytes"</l>
+ <l>one kilobyte is 2^10 bytes, or 1024 bytes</l>
+ <l>(you can print sums and variables in a sentence.</l>
+ <l> The commas seperating each section are a way of</l>
+ <l> seperating clearly different things that you are printing)</l>
+ <l></l>
+ <l>&gt;&gt;&gt; 21/3</l>
+ <l>7</l>
+ <l>&gt;&gt;&gt; 23/3</l>
+ <l>7</l>
+ <l>&gt;&gt;&gt; 23.0/3.0</l>
+ <l>7.6666...</l>
+ <l>(division, 2nd time ignoring remainder/decimals,</l>
+ <l> 3rd time including decimals)</l>
+ <l>&gt;&gt;&gt; 23%3</l>
+ <l>2</l>
+ <l>&gt;&gt;&gt; 49%10</l>
+ <l>9</l>
+ <l>(the remainder from a division)</l>
+ </code>
+ <p>As you see, there is the code, then the result of that code. I then explain them in brackets. These are the basic commands of python, and what they do. Here is a table to clarify them (because tables look cool, and make you feel smarter ;) ):</p>
+ <table title="Python operators">
+ <row>
+ <column title="command" width="25%" />
+ <column title="name" width="25%" />
+ <column title="example" width="25%" />
+ <column title="output" width="25%" />
+ </row>
+ <row>
+ <cell>+</cell>
+ <cell>Addition</cell>
+ <cell>4+5</cell>
+ <cell>9</cell>
+ </row>
+ <row>
+ <cell>-</cell>
+ <cell>Subtraction</cell>
+ <cell>8-5</cell>
+ <cell>3</cell>
+ </row>
+ <row>
+ <cell>*</cell>
+ <cell>Multiplication</cell>
+ <cell>4*5</cell>
+ <cell>20</cell>
+ </row>
+ <row>
+ <cell>/</cell>
+ <cell>Division</cell>
+ <cell>19/3</cell>
+ <cell>6</cell>
+ </row>
+ <row>
+ <cell>&#37;</cell>
+ <cell>Remainder</cell>
+ <cell>19&#37;3</cell>
+ <cell>5</cell>
+ </row>
+ <row>
+ <cell>**</cell>
+ <cell>Exponent</cell>
+ <cell>2**4</cell>
+ <cell>16</cell>
+ </row>
+ </table>
+ <p>Remember that thing called order of operation that they taught in maths? Well, it applies in python, too. Here it is, if you need reminding:</p>
+ <orderedList>
+ <li>parentheses ()</li>
+ <li>exponents **</li>
+ <li>multiplication *, division \, and remainder %</li>
+ <li>addition + and subtraction -</li>
+ </orderedList>
+ </section>
+ <section title="Order of Operations">
+ <p>Here are some examples that you might want to try, if you're rusty on this:</p>
+ <code title="Order of Operations">
+ <l>&gt;&gt;&gt; 1 + 2 * 3</l>
+ <l>7</l>
+ <l>&gt;&gt;&gt; (1 + 2) * 3</l>
+ <l>9</l>
+ </code>
+ <p>In the first example, the computer calculates 2 * 3 first, then adds 1 to it. This is because multiplication has the higher priority (at 3) and addition is below that (at lowly 4).</p>
+ <p>In the second example, the computer calculates 1 + 2 first, then multiplies it by 3. This is because parentheses (brackets, like the ones that are surrounding this interluding text ;) ) have the higher priority (at 1) and addition comes in later than that.</p>
+ <p>Also remember that the math is calculated from left to right, UNLESS you put in parentheses. The innermost parentheses are calculated first. Watch these examples:</p>
+ <code title="Parentheses">
+ <l>&gt;&gt;&gt; 4 - 40 - 3</l>
+ <l>-39</l>
+ <l>&gt;&gt;&gt; 4 - (40 - 3)</l>
+ <l>-33</l>
+ </code>
+ <p>In the first example, 4 -40 is calculated,then - 3 is done.</p>
+ <p>In the second example, 40 - 3 is calculated, then it is subtracted from 4.</p>
+ </section>
+ <section title="Comments, Please">
+ <p>The final thing you'll need to know to move on to multi-line programs is the comment. Type the following (and yes, the output is shown):</p>
+ <code title="comments">
+ <l>&gt;&gt;&gt; #I am a comment. Fear my wrath!</l>
+ <l></l>
+ <l>&gt;&gt;&gt;</l>
+ </code>
+ <p>A comment is a piece of code that is not run. In python, you make something a comment by putting a hash in front of it. A hash comments everything after it in the line, and nothing before it. So you could type this:</p>
+ <code title="comment examples">
+ <l>&gt;&gt;&gt; print "food is very nice" #eat me</l>
+ <l></l>
+ <l>food is very nice</l>
+ <l></l>
+ <l>(a normal output, without the smutty comment,</l>
+ <l>thankyou very much)</l>
+ <l></l>
+ <l>&gt;&gt;&gt;# print "food is very nice"</l>
+ <l></l>
+ <l>(nothing happens, because the code was after a comment)</l>
+ <l></l>
+ <l>&gt;&gt;&gt; print "food is very nice" eat me</l>
+ <l></l>
+ <l>(you'll get a fairly harmless error message,</l>
+ <l>because you didn't put your comment after a hash)</l>
+ </code>
+ <p>Comments are important for adding necessary information for another programmer to read, but not the computer. For example, an explanation of a section of code, saying what it does, or what is wrong with it. You can also comment bits of code by putting a # in front of it - if you don't want it to compile, but cant delete it because you might need it later.</p>
+ </section>
+ <section title="Conclusion">
+ <p>There you go! Lesson 2 Completed. That was even shorter than lesson 1!</p>
+ <p>Next lesson, we make programs with many lines of code, and save them, so we can actually send them to people. That's right, you don't have to retype every program you run! What an amazing innovation!</p>
+ <p>Thanks to all,</p>
+ <p>sthurlow.com</p>
+ </section>
+ </content>
+</lesson>
+</document>
137 lesson03/index.htm
@@ -0,0 +1,137 @@
+<html>
+<head>
+<title>Lesson 3 - Programs in a file, and variables</title>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
+<meta name="keywords" content="civilization,civ2,civ3,civ4,civilization iii,civilization ii,civilization iv,mod,python,xml,script,install" />
+<meta name="description" content="A Python and XML tutorial aimed at Civilization IV modding" />
+</head><link rel="stylesheet" type="text/css" href="../../stylesheet.css" />
+
+<body bgcolor="Teal">
+<div align="center" class="SidePanel">
+<div align="left" class="PaddingBig">
+<div class="MenuSection">
+<h1>Sthurlow.com</h1>
+<h2>Civilization IV Python tutorial</h2><h3>The Python Tutorial</h3>
+<p>The original sthurlow.com python tutorial</p>
+<p>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson01/">Installing Python</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson02/">Very Simple Programs</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson03/">Variables, Scripts</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson04/">Loops, Conditionals</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson05/">Functions</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson06/">Tuples, Lists, Dictionaries</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson07/">for Loop</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson08/">Classes</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson09/">Importing Modules</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson10/">File I/O</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson11/">Error Handling</a></div>
+</p>
+<h3>The Civ4 Programming Tutorial</h3>
+<p>All new Civ4 programming tutorial</p>
+<p>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/">Lesson 1 (not released)</a></div>
+</p>
+<br /><br /></div></div>
+</div>
+
+<div align="center" class="TextPanel">
+<div align="left" class="Padding"><h2>Programs in a file, and variables</h2>
+
+<h3>Introduction</h3>
+<p>Well, we can make one-liner programs. So What? You want to send programs to other people, so that they can use them, without knowing how to write them.</p>
+
+<h3>Editing in Notepad</h3>
+<p>Writing programs in python to a file is VERY easy. Python programs are simply text documents - you can open them up in notepad, and have a look at them, just like that. So, go and open notepad. Type the following:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 1 - mary.py</div>
+<div align="left" class="CodeBody">
+<pre>
+#A simple program.
+print "Mary had a little lamb,"
+print "it's fleece was white as snow;"
+print "and everywhere that Mary went",
+print "her lamb was sure to go."
+</pre>
+</div>
+</div><p>Keep this exactly the same, down to where the commas are placed. Save the file as 'mary.py' - and make sure notepad doesn't add .txt to the end of the filename - You will have to tell it to save as any file, to avoid this. Turn off 'Hide known file extensions' in Windows Explorer, if it makes it easier.</p>
+
+<h3>Using the IDLE Environment</h3>
+<p>Now, open up the Python IDLE program (should be in your start menu). Click 'File > Open' and find mary.py and open it. if you cant find mary.py, set the open dialogue to 'Files of type: All Files (*)'. A new window will open, showing the program you just wrote. To run your program, click 'Run>Run Module' (or just press F5). Your program will now run in the main Python screen (Titled *Python Shell*) and will look like this:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 2 - mary.py output</div>
+<div align="left" class="CodeBody">
+<pre>
+Mary had a little lamb,
+it's fleece was white as snow;
+and everywhere that Mary went her lamb was sure to go.
+</pre>
+</div>
+</div><p>You can also use IDLE to create Python programs, like what you did in notepad. Simply click 'File > New'. We will be writing all of our programs now in the python IDLE program - the notepad thing is just a demonstration to tell you that a .py file is just a simple text file, which anyone can see.</p>
+<p>There are a couple of things to notice here:</p>
+
+<ul><li>First of all, the comment wasn't shown. That is good, because remember - comments aren't compiled. (try compiling it after removing the # - it comes out messy)</li>
+<li>Second, is that the 3rd and 4th line got joined. This is because there is a comma just outside the inverted commas that surround the text. In the 'print' command, this stops the program from starting a new line on the screen when showing text.</li>
+<li>You can also run the program from your command line program (e.g. MSDOS) - Open the prompt up, type 'cd path\to\your\file' then type 'python mary.py'. Your program will now execute in the command line.</li>
+
+</ul>
+<h3>Variables</h3>
+<p>Now lets start introducing variables. Variables store a value, that can be looked at or changed at a later time. Let's make a program that uses variables. Open up IDLE, click 'File>New Window' - a new window now appears, and it is easy to type in programs. Type the following (or just copy and paste - just read very carefully, and compare the code to the output that the program will make):</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 3 - Variables</div>
+<div align="left" class="CodeBody">
+<pre>
+#variables demonstrated
+print "This program is a demo of variables"
+v = 1
+print "The value of v is now", v
+v = v + 1
+print "v now equals itself plus one, making it worth", v
+v = 51
+print "v can store any numerical value, to be used elsewhere."
+print "for example, in a sentence. v is now worth", v
+print "v times 5 equals", v*5
+print "but v still only remains", v
+print "to make v five times bigger, you would have to type v = v * 5"
+v = v * 5
+print "there you go, now v equals", v, "and not", v / 5
+</pre>
+</div>
+</div>
+<h3>Strings</h3>
+<p>As you can see, variables store values, for use at a later time. You can change them at any time. You can put in more than numbers, though. Variables can hold things like text. A variable that holds text is called a string. Try this program:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 4 - Strings</div>
+<div align="left" class="CodeBody">
+<pre>
+#giving variables text, and adding text.
+word1 = "Good"
+word2 = "Morning"
+word3 = "to you too!"
+print word1, word2
+sentence = word1 + " " + word2 + " " +word3
+print sentence
+</pre>
+</div>
+</div><p>The output will be:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 5 - String output</div>
+<div align="left" class="CodeBody">
+<pre>
+Good Morning
+Good Morning to you too!
+</pre>
+</div>
+</div><p>As you see, the variables above were holding text. Variable names can also be longer than one letter - here, we had word1, word2, and word3. As you can also see, strings can be added together to make longer words or sentences. However, it doesn't add spaces in between the words - hence me putting in the " " things (there is one space between those).</p>
+
+<h3>Conclusion</h3>
+<p>Well done! We now understand longer programs, and know the use of variables. Next lesson, we look at functions, what they are, and how to use them.</p>
+<p>Thanks to all,</p>
+<p>sthurlow.com</p>
+
+</div></div></body>
+</html>
77 lesson03/index.xml
@@ -0,0 +1,77 @@
+<document>
+<lesson number="3" title="Programs in a file, and variables" author="Steven Thurlow" style="../../stylesheet.css">
+ <content>
+ <section title="Introduction">
+ <p>Well, we can make one-liner programs. So What? You want to send programs to other people, so that they can use them, without knowing how to write them.</p>
+ </section>
+ <section title="Editing in Notepad">
+ <p>Writing programs in python to a file is VERY easy. Python programs are simply text documents - you can open them up in notepad, and have a look at them, just like that. So, go and open notepad. Type the following:</p>
+ <code title="mary.py">
+ <l>#A simple program.</l>
+ <l>print "Mary had a little lamb,"</l>
+ <l>print "it's fleece was white as snow;"</l>
+ <l>print "and everywhere that Mary went",</l>
+ <l>print "her lamb was sure to go."</l>
+ </code>
+ <p>Keep this exactly the same, down to where the commas are placed. Save the file as 'mary.py' - and make sure notepad doesn't add .txt to the end of the filename - You will have to tell it to save as any file, to avoid this. Turn off 'Hide known file extensions' in Windows Explorer, if it makes it easier.</p>
+ </section>
+ <section title="Using the IDLE Environment">
+ <p>Now, open up the Python IDLE program (should be in your start menu). Click 'File > Open' and find mary.py and open it. if you cant find mary.py, set the open dialogue to 'Files of type: All Files (*)'. A new window will open, showing the program you just wrote. To run your program, click 'Run>Run Module' (or just press F5). Your program will now run in the main Python screen (Titled *Python Shell*) and will look like this:</p>
+ <code title="mary.py output">
+ <l>Mary had a little lamb,</l>
+ <l>it's fleece was white as snow;</l>
+ <l>and everywhere that Mary went her lamb was sure to go.</l>
+ </code>
+ <p>You can also use IDLE to create Python programs, like what you did in notepad. Simply click 'File > New'. We will be writing all of our programs now in the python IDLE program - the notepad thing is just a demonstration to tell you that a .py file is just a simple text file, which anyone can see.</p>
+ <p>There are a couple of things to notice here:</p>
+ <unorderedList>
+ <entry>First of all, the comment wasn't shown. That is good, because remember - comments aren't compiled. (try compiling it after removing the # - it comes out messy)</entry>
+ <entry>Second, is that the 3rd and 4th line got joined. This is because there is a comma just outside the inverted commas that surround the text. In the 'print' command, this stops the program from starting a new line on the screen when showing text.</entry>
+ <entry>You can also run the program from your command line program (e.g. MSDOS) - Open the prompt up, type 'cd path\to\your\file' then type 'python mary.py'. Your program will now execute in the command line.</entry>
+ </unorderedList>
+ </section>
+ <section title="Variables">
+ <p>Now lets start introducing variables. Variables store a value, that can be looked at or changed at a later time. Let's make a program that uses variables. Open up IDLE, click 'File>New Window' - a new window now appears, and it is easy to type in programs. Type the following (or just copy and paste - just read very carefully, and compare the code to the output that the program will make):</p>
+ <code title="Variables">
+ <l>#variables demonstrated</l>
+ <l>print "This program is a demo of variables"</l>
+ <l>v = 1</l>
+ <l>print "The value of v is now", v</l>
+ <l>v = v + 1</l>
+ <l>print "v now equals itself plus one, making it worth", v</l>
+ <l>v = 51</l>
+ <l>print "v can store any numerical value, to be used elsewhere."</l>
+ <l>print "for example, in a sentence. v is now worth", v</l>
+ <l>print "v times 5 equals", v*5</l>
+ <l>print "but v still only remains", v</l>
+ <l>print "to make v five times bigger, you would have to type v = v * 5"</l>
+ <l>v = v * 5</l>
+ <l>print "there you go, now v equals", v, "and not", v / 5</l>
+ </code>
+ </section>
+ <section title="Strings">
+ <p>As you can see, variables store values, for use at a later time. You can change them at any time. You can put in more than numbers, though. Variables can hold things like text. A variable that holds text is called a string. Try this program:</p>
+ <code title="Strings">
+ <l>#giving variables text, and adding text.</l>
+ <l>word1 = "Good"</l>
+ <l>word2 = "Morning"</l>
+ <l>word3 = "to you too!"</l>
+ <l>print word1, word2</l>
+ <l>sentence = word1 + " " + word2 + " " +word3</l>
+ <l>print sentence</l>
+ </code>
+ <p>The output will be:</p>
+ <code title="String output">
+ <l>Good Morning</l>
+ <l>Good Morning to you too!</l>
+ </code>
+ <p>As you see, the variables above were holding text. Variable names can also be longer than one letter - here, we had word1, word2, and word3. As you can also see, strings can be added together to make longer words or sentences. However, it doesn't add spaces in between the words - hence me putting in the " " things (there is one space between those).</p>
+ </section>
+ <section title="Conclusion">
+ <p>Well done! We now understand longer programs, and know the use of variables. Next lesson, we look at functions, what they are, and how to use them.</p>
+ <p>Thanks to all,</p>
+ <p>sthurlow.com</p>
+ </section>
+ </content>
+</lesson>
+</document>
77 lesson03/index.xml~
@@ -0,0 +1,77 @@
+<tutorial>
+<lesson number="3" title="Programs in a file, and variables" author="Steven Thurlow">
+ <content>
+ <section title="Introduction">
+ <p>Well, we can make one-liner programs. So What? You want to send programs to other people, so that they can use them, without knowing how to write them.</p>
+ </section>
+ <section title="Editing in Notepad">
+ <p>Writing programs in python to a file is VERY easy. Python programs are simply text documents - you can open them up in notepad, and have a look at them, just like that. So, go and open notepad. Type the following:</p>
+ <code title="mary.py">
+ <l>#A simple program.</l>
+ <l>print "Mary had a little lamb,"</l>
+ <l>print "it's fleece was white as snow;"</l>
+ <l>print "and everywhere that Mary went",</l>
+ <l>print "her lamb was sure to go."</l>
+ </code>
+ <p>Keep this exactly the same, down to where the commas are placed. Save the file as 'mary.py' - and make sure notepad doesn't add .txt to the end of the filename - You will have to tell it to save as any file, to avoid this. Turn off 'Hide known file extensions' in Windows Explorer, if it makes it easier.</p>
+ </section>
+ <section title="Using the IDLE Environment">
+ <p>Now, open up the Python IDLE program (should be in your start menu). Click 'File > Open' and find mary.py and open it. if you cant find mary.py, set the open dialogue to 'Files of type: All Files (*)'. A new window will open, showing the program you just wrote. To run your program, click 'Run>Run Module' (or just press F5). Your program will now run in the main Python screen (Titled *Python Shell*) and will look like this:</p>
+ <code title="mary.py output">
+ <l>Mary had a little lamb,</l>
+ <l>it's fleece was white as snow;</l>
+ <l>and everywhere that Mary went her lamb was sure to go.</l>
+ </code>
+ <p>You can also use IDLE to create Python programs, like what you did in notepad. Simply click 'File > New'. We will be writing all of our programs now in the python IDLE program - the notepad thing is just a demonstration to tell you that a .py file is just a simple text file, which anyone can see.</p>
+ <p>There are a couple of things to notice here:</p>
+ <list state="unordered">
+ <entry>First of all, the comment wasn't shown. That is good, because remember - comments aren't compiled. (try compiling it after removing the # - it comes out messy)</entry>
+ <entry>Second, is that the 3rd and 4th line got joined. This is because there is a comma just outside the inverted commas that surround the text. In the 'print' command, this stops the program from starting a new line on the screen when showing text.</entry>
+ <entry>You can also run the program from your command line program (e.g. MSDOS) - Open the prompt up, type 'cd path\to\your\file' then type 'python mary.py'. Your program will now execute in the command line.</entry>
+ </list>
+ </section>
+ <section title="Variables">
+ <p>Now lets start introducing variables. Variables store a value, that can be looked at or changed at a later time. Let's make a program that uses variables. Open up IDLE, click 'File>New Window' - a new window now appears, and it is easy to type in programs. Type the following (or just copy and paste - just read very carefully, and compare the code to the output that the program will make):</p>
+ <code title="Variables">
+ <l>#variables demonstrated</l>
+ <l>print "This program is a demo of variables"</l>
+ <l>v = 1</l>
+ <l>print "The value of v is now", v</l>
+ <l>v = v + 1</l>
+ <l>print "v now equals itself plus one, making it worth", v</l>
+ <l>v = 51</l>
+ <l>print "v can store any numerical value, to be used elsewhere."</l>
+ <l>print "for example, in a sentence. v is now worth", v</l>
+ <l>print "v times 5 equals", v*5</l>
+ <l>print "but v still only remains", v</l>
+ <l>print "to make v five times bigger, you would have to type v = v * 5"</l>
+ <l>v = v * 5</l>
+ <l>print "there you go, now v equals", v, "and not", v / 5</l>
+ </code>
+ </section>
+ <section title="Strings">
+ <p>As you can see, variables store values, for use at a later time. You can change them at any time. You can put in more than numbers, though. Variables can hold things like text. A variable that holds text is called a string. Try this program:</p>
+ <code title="Strings">
+ <l>#giving variables text, and adding text.</l>
+ <l>word1 = "Good"</l>
+ <l>word2 = "Morning"</l>
+ <l>word3 = "to you too!"</l>
+ <l>print word1, word2</l>
+ <l>sentence = word1 + " " + word2 + " " +word3</l>
+ <l>print sentence</l>
+ </code>
+ <p>The output will be:</p>
+ <code title="String output">
+ <l>Good Morning</l>
+ <l>Good Morning to you too!</l>
+ </code>
+ <p>As you see, the variables above were holding text. Variable names can also be longer than one letter - here, we had word1, word2, and word3. As you can also see, strings can be added together to make longer words or sentences. However, it doesn't add spaces in between the words - hence me putting in the " " things (there is one space between those).</p>
+ </section>
+ <section title="Conclusion">
+ <p>Well done! We now understand longer programs, and know the use of variables. Next lesson, we look at functions, what they are, and how to use them.</p>
+ <p>Thanks to all,</p>
+ <p>sthurlow.com</p>
+ </section>
+ </content>
+</lesson>
+</tutorial>
319 lesson04/index.htm
@@ -0,0 +1,319 @@
+<html>
+<head>
+<title>Lesson 4 - Loops, Loops, Loops, Loops...</title>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
+<meta name="keywords" content="civilization,civ2,civ3,civ4,civilization iii,civilization ii,civilization iv,mod,python,xml,script,install" />
+<meta name="description" content="A Python and XML tutorial aimed at Civilization IV modding" />
+</head><link rel="stylesheet" type="text/css" href="../../stylesheet.css" />
+
+<body bgcolor="Teal">
+<div align="center" class="SidePanel">
+<div align="left" class="PaddingBig">
+<div class="MenuSection">
+<h1>Sthurlow.com</h1>
+<h2>Civilization IV Python tutorial</h2><h3>The Python Tutorial</h3>
+<p>The original sthurlow.com python tutorial</p>
+<p>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson01/">Installing Python</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson02/">Very Simple Programs</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson03/">Variables, Scripts</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson04/">Loops, Conditionals</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson05/">Functions</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson06/">Tuples, Lists, Dictionaries</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson07/">for Loop</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson08/">Classes</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson09/">Importing Modules</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson10/">File I/O</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson11/">Error Handling</a></div>
+</p>
+<h3>The Civ4 Programming Tutorial</h3>
+<p>All new Civ4 programming tutorial</p>
+<p>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/">Lesson 1 (not released)</a></div>
+</p>
+<br /><br /></div></div>
+</div>
+
+<div align="center" class="TextPanel">
+<div align="left" class="Padding"><h2>Loops, Loops, Loops, Loops...</h2>
+
+<h3>Introduction</h3>
+<p>(Our final lesson before we get into interacting with human input. Can't wait, can you?)</p>
+<p>Just imagine you needed a program to do something 20 times. What would you do? You could copy and paste the code 20 times, and have a virtually unreadable program, not to mention slow and pointless. Or, you could tell the computer to repeat a bit of code between point A and point B, until the time comes that you need it to stop. Such a thing is called a loop.</p>
+
+<h3>The 'while' loop</h3>
+<p>The following are examples of a type of loop, called the 'while' loop:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 1 - The while loop</div>
+<div align="left" class="CodeBody">
+<pre>
+a = 0
+while a < 10:
+ a = a + 1
+ print a
+</pre>
+</div>
+</div><p>How does this program work? Lets go through it in English:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 2 - plain-language while loop</div>
+<div align="left" class="CodeBody">
+<pre>
+'a' now equals 0
+As long as 'a' is less than 10, do the following:
+ Make 'a' one larger than what it already is.
+ print on-screen what 'a' is now worth.
+</pre>
+</div>
+</div><p>What does this do? Lets go through what the computer would be 'thinking' when it is in the 'while' loop:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 3 - while loop process</div>
+<div align="left" class="CodeBody">
+<pre>
+#JUST GLANCE OVER THIS QUICKLY
+#(It looks fancy, but is really simple)
+Is 'a' less than 10? YES (its 0)
+Make 'a' one larger (now 1)
+print on-screen what 'a' is (1)
+
+Is 'a' less than 10? YES (its 1)
+Make 'a' one larger (now 2)
+print on-screen what 'a' is (2)
+
+Is 'a' less than 10? YES (its 2)
+Make 'a' one larger (now 3)
+print on-screen what 'a' is (3)
+
+Is 'a' less than 10? YES (its 3)
+Make 'a' one larger (now 4)
+print on-screen what 'a' is (4)
+
+Is 'a' less than 10? YES (its 4)
+Make 'a' one larger (now 5)
+print on-screen what 'a' is (5)
+
+Is 'a' less than 10? YES (its 5)
+Make 'a' one larger (now 6)
+print on-screen what 'a' is (6)
+
+Is 'a' less than 10? YES (its 6)
+Make 'a' one larger (now 7)
+print on-screen what 'a' is (7)
+
+Is 'a' less than 10? YES (are you still here?)
+Make 'a' one larger (now 8)
+print on-screen what 'a' is (8)
+
+Is 'a' less than 10? YES (its 8)
+Make 'a' one larger (now 9)
+print on-screen what 'a' is (9)
+
+Is 'a' less than 10? YES (its 9)
+Make 'a' one larger (now 10)
+print on-screen what 'a' is (10)
+
+Is 'a' less than 10? NO (its 10, therefore isn't less than 10)
+Don't do the loop
+There's no code left to do, so the program ends
+</pre>
+</div>
+</div><p>So in short, try to think of it that way when you write 'while' loops. This is how you write them, by the way (and a couple of examples:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 4 - while loop form, and example</div>
+<div align="left" class="CodeBody">
+<pre>
+while {condition that the loop continues}:
+ {what to do in the loop}
+ {have it indented, usually four spaces}
+{the code here is not looped}
+{because it isn't indented}
+
+#EXAMPLE
+#Type this in, see what it does
+x = 10
+while x != 0:
+ print x
+ x = x - 1
+ print "wow, we've counted x down, and now it equals", x
+print "And now the loop has ended."
+</pre>
+</div>
+</div><p>Remember, to make a program, you open IDLE, click File > New Window, type your program in the new window, then press F5 to run.</p>
+
+<h3>Boolean Expressions (Boolean... what?!?)</h3>
+<p>What do you type in the area marked {conditions that the loop continues}? The answer is a boolean expression.</p>
+<p>What? A forgotten concept for the non-math people here. Never mind, boolean expression just means a question that can be answered with a TRUE or FALSE response. For example, if you wanted to say your age is the same as the person next to you, you would type:</p>
+<p>My age == the age of the person next to me</p>
+<p>And the statement would be TRUE. If you were younger than the person opposite, you'd say:</p>
+<p>My age < the age of the person opposite me</p>
+<p>And the statement would be TRUE. If, however, you were to say the following, and the person opposite of you was younger than you:</p>
+<p>My age < the age of the person opposite me</p>
+<p>The statement would be FALSE - the truth is that it is the other way around. This is how a loop thinks - if the expression is true, keep looping. If it is false, don't loop. With this in mind, lets have a look at the operators (symbols that represent an action) that are involved in boolean expressions:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Table 1 - Boolean operators</div>
+<table class="TableBody">
+<tr>
+<td class="TableContent" width="20%"><b>Expression</b></td>
+<td class="TableContent" width="80%"><b>Function</b></td>
+</tr>
+<tr>
+<td class="TableContent"><</td>
+<td class="TableContent">less than</td>
+</tr>
+<tr>
+<td class="TableContent"><=</td>
+<td class="TableContent">less that or equal to</td>
+</tr>
+<tr>
+<td class="TableContent">></td>
+<td class="TableContent">greater than</td>
+</tr>
+<tr>
+<td class="TableContent">>=</td>
+<td class="TableContent">greater than or equal to</td>
+</tr>
+<tr>
+<td class="TableContent">!=</td>
+<td class="TableContent">not equal to</td>
+</tr>
+<tr>
+<td class="TableContent"><></td>
+<td class="TableContent">not equal to (alternate)</td>
+</tr>
+<tr>
+<td class="TableContent">==</td>
+<td class="TableContent">equal to</td>
+</tr>
+</table>
+</div><br /><p>Dont get '=' and '==' mixed up - the '=' operator makes what is on the left equal to what is on the right. the '==' operator says whether the thing on the left is the same as what is on the right, and returns true or false.</p>
+
+<h3>Conditional Statements</h3>
+<p>OK! We've (hopefully) covered 'while' loops. Now let's look at something a little different - conditionals.</p>
+<p>Conditionals are where a section of code is only run if certain conditions are met. This is similar to the 'while' loop you just wrote, which only runs when x doesn't equal 0. However, Conditionals are only run once. The most common conditional in any program language, is the 'if' statement. Here is how it works:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 5 - if statement and example</div>
+<div align="left" class="CodeBody">
+<pre>
+if {conditions to be met}:
+ {do this}
+ {and this}
+ {and this}
+{but this happens regardless}
+{because it isn't indented}
+
+#EXAMPLE 1
+y = 1
+if y == 1:
+ print "y still equals 1, I was just checking"
+
+#EXAMPLE 2
+print "We will show the even numbers up to 20"
+n = 1
+while n <= 20:
+ if n % 2 == 0:
+ print n
+ n = n + 1
+print "there, done."
+</pre>
+</div>
+</div><p>Example 2 there looks tricky. But all we have done is run an 'if' statement every time the 'while' loop runs. Remember that the % just means the remainder from a division - just checking that there is nothing left over if the number is divided by two - showing it is even. If it is even, it prints what 'n' is.</p>
+
+<h3>'else' and 'elif' - When it Ain't True</h3>
+<p>There are many ways you can use the 'if' statement, do deal with situations where your boolean expression ends up FALSE. They are 'else' and 'elif'.</p>
+<p>'else' simply tells the computer what to do if the conditions of 'if' arent met. For example, read the following:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 6 - the else statement</div>
+<div align="left" class="CodeBody">
+<pre>
+a = 1
+if a > 5:
+ print "This shouldn't happen."
+else:
+ print "This should happen."
+</pre>
+</div>
+</div><p>'a' is not greater than five, therefore what is under 'else' is done.</p>
+<p>'elif' is just a shortened way of saying 'else if'. When the 'if' statement fails to be true, 'elif' will do what is under it IF the conditions are met. For example:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 7 - The elif statement</div>
+<div align="left" class="CodeBody">
+<pre>
+z = 4
+if z > 70:
+ print "Something is very wrong"
+elif z < 7:
+ print "This is normal"
+</pre>
+</div>
+</div><p>The 'if' statement, along with 'else' and 'elif' follow this form:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 8 - the complete if syntax</div>
+<div align="left" class="CodeBody">
+<pre>
+if {conditions}:
+ {run this code}
+elif {conditions}:
+ {run this code}
+elif {conditions}:
+ {run this code}
+else:
+ {run this code}
+
+#You can have as many or as little elif statements as you need
+#anywhere from zero to the sky.
+#You can have at most one else statement
+#and only after all other ifs and elifs.
+</pre>
+</div>
+</div><p>One of the most important points to remember is that you MUST have a colon : at the end of every line with an 'if', 'elif', 'else' or 'while' in it. I forgot that, and as a result a stack of people got stumped at this lesson (sorry ;) ).</p>
+
+<h3>Indentation</h3>
+<p>One other point is that the code to be executed if the conditions are met, MUST BE INDENTED. That means that if you want to loop the next five lines with a 'while' loop, you must put a set number of spaces at the beginning of each of the next five lines. This is good programming practice in any language, but python requires that you do it. Here is an example of both of the above points:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 9 - Indentation</div>
+<div align="left" class="CodeBody">
+<pre>
+a = 10
+while a > 0:
+ print a
+ if a > 5:
+ print "Big number!"
+ elif a % 2 != 0:
+ print "This is an odd number"
+ print "It isn't greater than five, either"
+ else:
+ print "this number isn't greater than 5"
+ print "nor is it odd"
+ print "feeling special?"
+ a = a - 1
+ print "we just made 'a' one less than what it was!"
+ print "and unless a is not greater than 0, we'll do the loop again."
+print "well, it seems as if 'a' is now no bigger than 0!"
+print "the loop is now over, and without furthur adue, so is this program!"
+</pre>
+</div>
+</div><p>Notice the three levels of indents there:</p>
+<ol>
+<li>Each line in the first level starts with no spaces. It is the main program, and will always execute.</li>
+<li>Each line in the second level starts with four spaces. When there is an 'if' or loop on the first level, everything on the second level after that will be looped/'ifed', until a new line starts back on the first level again.</li>
+<li>Each line in the third level starts with eight spaces. When there is an 'if' or loop on the second level, everything on the third level after that will be looped/'ifed', until a new line starts back on the second level again.</li>
+<li>This goes on infinitely, until the person writing the program has an internal brain explosion, and cannot understand anything he/she has written.</li>
+</ol>
+<p>There is another loop, called the 'for' loop, but we will cover that in a later lesson, after we have learnt about lists.</p>
+
+<h3>Conclusion</h3>
+<p>And that is lesson 4! In lesson 5, we get into user interaction, and writing programs that actually serve a purpose. Can't wait!</p>
+<p>Thanks to all,</p>
+<p>sthurlow.com</p>
+
+</div></div></body>
+</html>
236 lesson04/index.xml
@@ -0,0 +1,236 @@
+<document>
+<lesson number="4" title="Loops, Loops, Loops, Loops..." author="Steven Thurlow" style="../../stylesheet.css">
+ <content>
+ <section title="Introduction">
+ <p>(Our final lesson before we get into interacting with human input. Can't wait, can you?)</p>
+ <p>Just imagine you needed a program to do something 20 times. What would you do? You could copy and paste the code 20 times, and have a virtually unreadable program, not to mention slow and pointless. Or, you could tell the computer to repeat a bit of code between point A and point B, until the time comes that you need it to stop. Such a thing is called a loop.</p>
+ </section>
+ <section title="The 'while' loop">
+ <p>The following are examples of a type of loop, called the 'while' loop:</p>
+ <code title="The while loop">
+ <l>a = 0</l>
+ <l>while a &lt; 10:</l>
+ <l> a = a + 1</l>
+ <l> print a</l>
+ </code>
+ <p>How does this program work? Lets go through it in English:</p>
+ <code title="plain-language while loop">
+ <l>'a' now equals 0</l>
+ <l>As long as 'a' is less than 10, do the following:</l>
+ <l> Make 'a' one larger than what it already is.</l>
+ <l> print on-screen what 'a' is now worth.</l>
+ </code>
+ <p>What does this do? Lets go through what the computer would be 'thinking' when it is in the 'while' loop:</p>
+ <code title="while loop process">
+ <l>#JUST GLANCE OVER THIS QUICKLY</l>
+ <l>#(It looks fancy, but is really simple)</l>
+ <l>Is 'a' less than 10? YES (its 0)</l>
+ <l>Make 'a' one larger (now 1)</l>
+ <l>print on-screen what 'a' is (1)</l>
+ <l></l>
+ <l>Is 'a' less than 10? YES (its 1)</l>
+ <l>Make 'a' one larger (now 2)</l>
+ <l>print on-screen what 'a' is (2)</l>
+ <l></l>
+ <l>Is 'a' less than 10? YES (its 2)</l>
+ <l>Make 'a' one larger (now 3)</l>
+ <l>print on-screen what 'a' is (3)</l>
+ <l></l>
+ <l>Is 'a' less than 10? YES (its 3)</l>
+ <l>Make 'a' one larger (now 4)</l>
+ <l>print on-screen what 'a' is (4)</l>
+ <l></l>
+ <l>Is 'a' less than 10? YES (its 4)</l>
+ <l>Make 'a' one larger (now 5)</l>
+ <l>print on-screen what 'a' is (5)</l>
+ <l></l>
+ <l>Is 'a' less than 10? YES (its 5)</l>
+ <l>Make 'a' one larger (now 6)</l>
+ <l>print on-screen what 'a' is (6)</l>
+ <l></l>
+ <l>Is 'a' less than 10? YES (its 6)</l>
+ <l>Make 'a' one larger (now 7)</l>
+ <l>print on-screen what 'a' is (7)</l>
+ <l></l>
+ <l>Is 'a' less than 10? YES (are you still here?)</l>
+ <l>Make 'a' one larger (now 8)</l>
+ <l>print on-screen what 'a' is (8)</l>
+ <l></l>
+ <l>Is 'a' less than 10? YES (its 8)</l>
+ <l>Make 'a' one larger (now 9)</l>
+ <l>print on-screen what 'a' is (9)</l>
+ <l></l>
+ <l>Is 'a' less than 10? YES (its 9)</l>
+ <l>Make 'a' one larger (now 10)</l>
+ <l>print on-screen what 'a' is (10)</l>
+ <l></l>
+ <l>Is 'a' less than 10? NO (its 10, therefore isn't less than 10)</l>
+ <l>Don't do the loop</l>
+ <l>There's no code left to do, so the program ends</l>
+ </code>
+ <p>So in short, try to think of it that way when you write 'while' loops. This is how you write them, by the way (and a couple of examples:</p>
+ <code title="while loop form, and example">
+ <l>while {condition that the loop continues}:</l>
+ <l> {what to do in the loop}</l>
+ <l> {have it indented, usually four spaces}</l>
+ <l>{the code here is not looped}</l>
+ <l>{because it isn't indented}</l>
+ <l></l>
+ <l>#EXAMPLE</l>
+ <l>#Type this in, see what it does</l>
+ <l>x = 10</l>
+ <l>while x != 0:</l>
+ <l> print x</l>
+ <l> x = x - 1</l>
+ <l> print "wow, we've counted x down, and now it equals", x</l>
+ <l>print "And now the loop has ended."</l>
+ </code>
+ <p>Remember, to make a program, you open IDLE, click File > New Window, type your program in the new window, then press F5 to run.</p>
+ </section>
+ <section title="Boolean Expressions (Boolean... what?!?)">
+ <p>What do you type in the area marked {conditions that the loop continues}? The answer is a boolean expression.</p>
+ <p>What? A forgotten concept for the non-math people here. Never mind, boolean expression just means a question that can be answered with a TRUE or FALSE response. For example, if you wanted to say your age is the same as the person next to you, you would type:</p>
+ <p>My age == the age of the person next to me</p>
+ <p>And the statement would be TRUE. If you were younger than the person opposite, you'd say:</p>
+ <p>My age &lt; the age of the person opposite me</p>
+ <p>And the statement would be TRUE. If, however, you were to say the following, and the person opposite of you was younger than you:</p>
+ <p>My age &lt; the age of the person opposite me</p>
+ <p>The statement would be FALSE - the truth is that it is the other way around. This is how a loop thinks - if the expression is true, keep looping. If it is false, don't loop. With this in mind, lets have a look at the operators (symbols that represent an action) that are involved in boolean expressions:</p>
+ <table title="Boolean operators">
+ <row>
+ <column title="Expression" width="20%"/>
+ <column title="Function" width="80%"/>
+ </row>
+ <row>
+ <cell>&lt;</cell>
+ <cell>less than</cell>
+ </row>
+ <row>
+ <cell>&lt;=</cell>
+ <cell>less that or equal to</cell>
+ </row>
+ <row>
+ <cell>&gt;</cell>
+ <cell>greater than</cell>
+ </row>
+ <row>
+ <cell>&gt;=</cell>
+ <cell>greater than or equal to</cell>
+ </row>
+ <row>
+ <cell>!=</cell>
+ <cell>not equal to</cell>
+ </row>
+ <row>
+ <cell>&lt;&gt;</cell>
+ <cell>not equal to (alternate)</cell>
+ </row>
+ <row>
+ <cell>==</cell>
+ <cell>equal to</cell>
+ </row>
+ </table>
+ <p>Dont get '=' and '==' mixed up - the '=' operator makes what is on the left equal to what is on the right. the '==' operator says whether the thing on the left is the same as what is on the right, and returns true or false.</p>
+ </section>
+ <section title="Conditional Statements">
+ <p>OK! We've (hopefully) covered 'while' loops. Now let's look at something a little different - conditionals.</p>
+ <p>Conditionals are where a section of code is only run if certain conditions are met. This is similar to the 'while' loop you just wrote, which only runs when x doesn't equal 0. However, Conditionals are only run once. The most common conditional in any program language, is the 'if' statement. Here is how it works:</p>
+ <code title="if statement and example">
+ <l>if {conditions to be met}:</l>
+ <l> {do this}</l>
+ <l> {and this}</l>
+ <l> {and this}</l>
+ <l>{but this happens regardless}</l>
+ <l>{because it isn't indented}</l>
+ <l></l>
+ <l>#EXAMPLE 1</l>
+ <l>y = 1</l>
+ <l>if y == 1:</l>
+ <l> print "y still equals 1, I was just checking"</l>
+ <l></l>
+ <l>#EXAMPLE 2</l>
+ <l>print "We will show the even numbers up to 20"</l>
+ <l>n = 1</l>
+ <l>while n &lt;= 20:</l>
+ <l> if n % 2 == 0:</l>
+ <l> print n</l>
+ <l> n = n + 1</l>
+ <l>print "there, done."</l>
+ </code>
+ <p>Example 2 there looks tricky. But all we have done is run an 'if' statement every time the 'while' loop runs. Remember that the % just means the remainder from a division - just checking that there is nothing left over if the number is divided by two - showing it is even. If it is even, it prints what 'n' is.</p>
+ </section>
+ <section title="'else' and 'elif' - When it Ain't True">
+ <p>There are many ways you can use the 'if' statement, do deal with situations where your boolean expression ends up FALSE. They are 'else' and 'elif'.</p>
+ <p>'else' simply tells the computer what to do if the conditions of 'if' arent met. For example, read the following:</p>
+ <code title="the else statement">
+ <l>a = 1</l>
+ <l>if a &gt; 5:</l>
+ <l> print "This shouldn't happen."</l>
+ <l>else:</l>
+ <l> print "This should happen."</l>
+ </code>
+ <p>'a' is not greater than five, therefore what is under 'else' is done.</p>
+ <p>'elif' is just a shortened way of saying 'else if'. When the 'if' statement fails to be true, 'elif' will do what is under it IF the conditions are met. For example:</p>
+ <code title="The elif statement">
+ <l>z = 4</l>
+ <l>if z &gt; 70:</l>
+ <l> print "Something is very wrong"</l>
+ <l>elif z &lt; 7:</l>
+ <l> print "This is normal"</l>
+ </code>
+ <p>The 'if' statement, along with 'else' and 'elif' follow this form:</p>
+ <code title="the complete if syntax">
+ <l>if {conditions}:</l>
+ <l> {run this code}</l>
+ <l>elif {conditions}:</l>
+ <l> {run this code}</l>
+ <l>elif {conditions}:</l>
+ <l> {run this code}</l>
+ <l>else:</l>
+ <l> {run this code}</l>
+ <l></l>
+ <l>#You can have as many or as little elif statements as you need</l>
+ <l>#anywhere from zero to the sky.</l>
+ <l>#You can have at most one else statement</l>
+ <l>#and only after all other ifs and elifs.</l>
+ </code>
+ <p>One of the most important points to remember is that you MUST have a colon : at the end of every line with an 'if', 'elif', 'else' or 'while' in it. I forgot that, and as a result a stack of people got stumped at this lesson (sorry ;) ).</p>
+ </section>
+ <section title="Indentation">
+ <p>One other point is that the code to be executed if the conditions are met, MUST BE INDENTED. That means that if you want to loop the next five lines with a 'while' loop, you must put a set number of spaces at the beginning of each of the next five lines. This is good programming practice in any language, but python requires that you do it. Here is an example of both of the above points:</p>
+ <code title="Indentation">
+ <l>a = 10</l>
+ <l>while a &gt; 0:</l>
+ <l> print a</l>
+ <l> if a &gt; 5:</l>
+ <l> print "Big number!"</l>
+ <l> elif a % 2 != 0:</l>
+ <l> print "This is an odd number"</l>
+ <l> print "It isn't greater than five, either"</l>
+ <l> else:</l>
+ <l> print "this number isn't greater than 5"</l>
+ <l> print "nor is it odd"</l>
+ <l> print "feeling special?"</l>
+ <l> a = a - 1</l>
+ <l> print "we just made 'a' one less than what it was!"</l>
+ <l> print "and unless a is not greater than 0, we'll do the loop again."</l>
+ <l>print "well, it seems as if 'a' is now no bigger than 0!"</l>
+ <l>print "the loop is now over, and without furthur adue, so is this program!"</l>
+ </code>
+ <p>Notice the three levels of indents there:</p>
+ <orderedList>
+ <entry>Each line in the first level starts with no spaces. It is the main program, and will always execute.</entry>
+ <entry>Each line in the second level starts with four spaces. When there is an 'if' or loop on the first level, everything on the second level after that will be looped/'ifed', until a new line starts back on the first level again.</entry>
+ <entry>Each line in the third level starts with eight spaces. When there is an 'if' or loop on the second level, everything on the third level after that will be looped/'ifed', until a new line starts back on the second level again.</entry>
+ <entry>This goes on infinitely, until the person writing the program has an internal brain explosion, and cannot understand anything he/she has written.</entry>
+ </orderedList>
+ <p>There is another loop, called the 'for' loop, but we will cover that in a later lesson, after we have learnt about lists.</p>
+ </section>
+ <section title="Conclusion">
+ <p>And that is lesson 4! In lesson 5, we get into user interaction, and writing programs that actually serve a purpose. Can't wait!</p>
+ <p>Thanks to all,</p>
+ <p>sthurlow.com</p>
+ </section>
+ </content>
+</lesson>
+</document>
236 lesson04/index.xml~
@@ -0,0 +1,236 @@
+<document>
+<lesson number="4" title="Loops, Loops, Loops, Loops..." author="Steven Thurlow" style="../../stylesheet.css">
+ <content>
+ <section title="Introduction">
+ <p>(Our final lesson before we get into interacting with human input. Can't wait, can you?)</p>
+ <p>Just imagine you needed a program to do something 20 times. What would you do? You could copy and paste the code 20 times, and have a virtually unreadable program, not to mention slow and pointless. Or, you could tell the computer to repeat a bit of code between point A and point B, until the time comes that you need it to stop. Such a thing is called a loop.</p>
+ </section>
+ <section title="The 'while' loop">
+ <p>The following are examples of a type of loop, called the 'while' loop:</p>
+ <code title="The while loop">
+ <l>a = 0</l>
+ <l>while a &lt; 10:</l>
+ <l> a = a + 1</l>
+ <l> print a</l>
+ </code>
+ <p>How does this program work? Lets go through it in English:</p>
+ <code title="plain-language while loop">
+ <l>'a' now equals 0</l>
+ <l>As long as 'a' is less than 10, do the following:</l>
+ <l> Make 'a' one larger than what it already is.</l>
+ <l> print on-screen what 'a' is now worth.</l>
+ </code>
+ <p>What does this do? Lets go through what the computer would be 'thinking' when it is in the 'while' loop:</p>
+ <code title="while loop process">
+ <l>#JUST GLANCE OVER THIS QUICKLY</l>
+ <l>#(It looks fancy, but is really simple)</l>
+ <l>Is 'a' less than 10? YES (its 0)</l>
+ <l>Make 'a' one larger (now 1)</l>
+ <l>print on-screen what 'a' is (1)</l>
+ <l></l>
+ <l>Is 'a' less than 10? YES (its 1)</l>
+ <l>Make 'a' one larger (now 2)</l>
+ <l>print on-screen what 'a' is (2)</l>
+ <l></l>
+ <l>Is 'a' less than 10? YES (its 2)</l>
+ <l>Make 'a' one larger (now 3)</l>
+ <l>print on-screen what 'a' is (3)</l>
+ <l></l>
+ <l>Is 'a' less than 10? YES (its 3)</l>
+ <l>Make 'a' one larger (now 4)</l>
+ <l>print on-screen what 'a' is (4)</l>
+ <l></l>
+ <l>Is 'a' less than 10? YES (its 4)</l>
+ <l>Make 'a' one larger (now 5)</l>
+ <l>print on-screen what 'a' is (5)</l>
+ <l></l>
+ <l>Is 'a' less than 10? YES (its 5)</l>
+ <l>Make 'a' one larger (now 6)</l>
+ <l>print on-screen what 'a' is (6)</l>
+ <l></l>
+ <l>Is 'a' less than 10? YES (its 6)</l>
+ <l>Make 'a' one larger (now 7)</l>
+ <l>print on-screen what 'a' is (7)</l>
+ <l></l>
+ <l>Is 'a' less than 10? YES (are you still here?)</l>
+ <l>Make 'a' one larger (now 8)</l>
+ <l>print on-screen what 'a' is (8)</l>
+ <l></l>
+ <l>Is 'a' less than 10? YES (its 8)</l>
+ <l>Make 'a' one larger (now 9)</l>
+ <l>print on-screen what 'a' is (9)</l>
+ <l></l>
+ <l>Is 'a' less than 10? YES (its 9)</l>
+ <l>Make 'a' one larger (now 10)</l>
+ <l>print on-screen what 'a' is (10)</l>
+ <l></l>
+ <l>Is 'a' less than 10? NO (its 10, therefore isn't less than 10)</l>
+ <l>Don't do the loop</l>
+ <l>There's no code left to do, so the program ends</l>
+ </code>
+ <p>So in short, try to think of it that way when you write 'while' loops. This is how you write them, by the way (and a couple of examples:</p>
+ <code title="while loop form, and example">
+ <l>while {condition that the loop continues}:</l>
+ <l> {what to do in the loop}</l>
+ <l> {have it indented, usually four spaces}</l>
+ <l>{the code here is not looped}</l>
+ <l>{because it isn't indented}</l>
+ <l></l>
+ <l>#EXAMPLE</l>
+ <l>#Type this in, see what it does</l>
+ <l>x = 10</l>
+ <l>while x != 0:</l>
+ <l> print x</l>
+ <l> x = x - 1</l>
+ <l> print "wow, we've counted x down, and now it equals", x</l>
+ <l>print "And now the loop has ended."</l>
+ </code>
+ <p>Remember, to make a program, you open IDLE, click File > New Window, type your program in the new window, then press F5 to run.</p>
+ </section>
+ <section title="Boolean Expressions (Boolean... what?!?)">
+ <p>What do you type in the area marked {conditions that the loop continues}? The answer is a boolean expression.</p>
+ <p>What? A forgotten concept for the non-math people here. Never mind, boolean expression just means a question that can be answered with a TRUE or FALSE response. For example, if you wanted to say your age is the same as the person next to you, you would type:</p>
+ <p>My age == the age of the person next to me</p>
+ <p>And the statement would be TRUE. If you were younger than the person opposite, you'd say:</p>
+ <p>My age &lt; the age of the person opposite me</p>
+ <p>And the statement would be TRUE. If, however, you were to say the following, and the person opposite of you was younger than you:</p>
+ <p>My age &lt; the age of the person opposite me</p>
+ <p>The statement would be FALSE - the truth is that it is the other way around. This is how a loop thinks - if the expression is true, keep looping. If it is false, don't loop. With this in mind, lets have a look at the operators (symbols that represent an action) that are involved in boolean expressions:</p>
+ <table title="Boolean operators">
+ <row>
+ <column title="Expression" width="20%"/>
+ <column title="Function" width="80%"/>
+ </row>
+ <row>
+ <cell>&lt;</cell>
+ <cell>less than</cell>
+ </row>
+ <row>
+ <cell>&lt;=</cell>
+ <cell>less that or equal to</cell>
+ </row>
+ <row>
+ <cell>&gt;</cell>
+ <cell>greater than</cell>
+ </row>
+ <row>
+ <cell>&gt;=</cell>
+ <cell>greater than or equal to</cell>
+ </row>
+ <row>
+ <cell>!=</cell>
+ <cell>not equal to</cell>
+ </row>
+ <row>
+ <cell>&lt;&gt;</cell>
+ <cell>not equal to (alternate)</cell>
+ </row>
+ <row>
+ <cell>==</cell>
+ <cell>equal to</cell>
+ </row>
+ </table>
+ <p>Dont get '=' and '==' mixed up - the '=' operator makes what is on the left equal to what is on the right. the '==' operator says whether the thing on the left is the same as what is on the right, and returns true or false.</p>
+ </section>
+ <section title="Conditional Statements">
+ <p>OK! We've (hopefully) covered 'while' loops. Now let's look at something a little different - conditionals.</p>
+ <p>Conditionals are where a section of code is only run if certain conditions are met. This is similar to the 'while' loop you just wrote, which only runs when x doesn't equal 0. However, Conditionals are only run once. The most common conditional in any program language, is the 'if' statement. Here is how it works:</p>
+ <code title="if statement and example">
+ <l>if {conditions to be met}:</l>
+ <l> {do this}</l>
+ <l> {and this}</l>
+ <l> {and this}</l>
+ <l>{but this happens regardless}</l>
+ <l>{because it isn't indented}</l>
+ <l></l>
+ <l>#EXAMPLE 1</l>
+ <l>y = 1</l>
+ <l>if y == 1:</l>
+ <l> print "y still equals 1, I was just checking"</l>
+ <l></l>
+ <l>#EXAMPLE 2</l>
+ <l>print "We will show the odd numbers up to 20"</l>
+ <l>n = 1</l>
+ <l>while n &lt;= 20:</l>
+ <l> if n % 2 == 0:</l>
+ <l> print n</l>
+ <l> n = n + 1</l>
+ <l>print "there, done."</l>
+ </code>
+ <p>Example 2 there looks tricky. But all we have done is run an 'if' statement every time the 'while' loop runs. Remember that the % just means the remainder from a division - just checking that there is nothing left over if the number is divided by two - showing it is even. If it is even, it prints what 'n' is.</p>
+ </section>
+ <section title="'else' and 'elif' - When it Ain't True">
+ <p>There are many ways you can use the 'if' statement, do deal with situations where your boolean expression ends up FALSE. They are 'else' and 'elif'.</p>
+ <p>'else' simply tells the computer what to do if the conditions of 'if' arent met. For example, read the following:</p>
+ <code title="the else statement">
+ <l>a = 1</l>
+ <l>if a &gt; 5:</l>
+ <l> print "This shouldn't happen."</l>
+ <l>else:</l>
+ <l> print "This should happen."</l>
+ </code>
+ <p>'a' is not greater than five, therefore what is under 'else' is done.</p>
+ <p>'elif' is just a shortened way of saying 'else if'. When the 'if' statement fails to be true, 'elif' will do what is under it IF the conditions are met. For example:</p>
+ <code title="The elif statement">
+ <l>z = 4</l>
+ <l>if z &gt; 70:</l>
+ <l> print "Something is very wrong"</l>
+ <l>elif z &lt; 7:</l>
+ <l> print "This is normal"</l>
+ </code>
+ <p>The 'if' statement, along with 'else' and 'elif' follow this form:</p>
+ <code title="the complete if syntax">
+ <l>if {conditions}:</l>
+ <l> {run this code}</l>
+ <l>elif {conditions}:</l>
+ <l> {run this code}</l>
+ <l>elif {conditions}:</l>
+ <l> {run this code}</l>
+ <l>else:</l>
+ <l> {run this code}</l>
+ <l></l>
+ <l>#You can have as many or as little elif statements as you need</l>
+ <l>#anywhere from zero to the sky.</l>
+ <l>#You can have at most one else statement</l>
+ <l>#and only after all other ifs and elifs.</l>
+ </code>
+ <p>One of the most important points to remember is that you MUST have a colon : at the end of every line with an 'if', 'elif', 'else' or 'while' in it. I forgot that, and as a result a stack of people got stumped at this lesson (sorry ;) ).</p>
+ </section>
+ <section title="Indentation">
+ <p>One other point is that the code to be executed if the conditions are met, MUST BE INDENTED. That means that if you want to loop the next five lines with a 'while' loop, you must put a set number of spaces at the beginning of each of the next five lines. This is good programming practice in any language, but python requires that you do it. Here is an example of both of the above points:</p>
+ <code title="Indentation">
+ <l>a = 10</l>
+ <l>while a &gt; 0:</l>
+ <l> print a</l>
+ <l> if a &gt; 5:</l>
+ <l> print "Big number!"</l>
+ <l> elif a % 2 != 0:</l>
+ <l> print "This is an odd number"</l>
+ <l> print "It isn't greater than five, either"</l>
+ <l> else:</l>
+ <l> print "this number isn't greater than 5"</l>
+ <l> print "nor is it odd"</l>
+ <l> print "feeling special?"</l>
+ <l> a = a - 1</l>
+ <l> print "we just made 'a' one less than what it was!"</l>
+ <l> print "and unless a is not greater than 0, we'll do the loop again."</l>
+ <l>print "well, it seems as if 'a' is now no bigger than 0!"</l>
+ <l>print "the loop is now over, and without furthur adue, so is this program!"</l>
+ </code>
+ <p>Notice the three levels of indents there:</p>
+ <orderedList>
+ <entry>Each line in the first level starts with no spaces. It is the main program, and will always execute.</entry>
+ <entry>Each line in the second level starts with four spaces. When there is an 'if' or loop on the first level, everything on the second level after that will be looped/'ifed', until a new line starts back on the first level again.</entry>
+ <entry>Each line in the third level starts with eight spaces. When there is an 'if' or loop on the second level, everything on the third level after that will be looped/'ifed', until a new line starts back on the second level again.</entry>
+ <entry>This goes on infinitely, until the person writing the program has an internal brain explosion, and cannot understand anything he/she has written.</entry>
+ </orderedList>
+ <p>There is another loop, called the 'for' loop, but we will cover that in a later lesson, after we have learnt about lists.</p>
+ </section>
+ <section title="Conclusion">
+ <p>And that is lesson 4! In lesson 5, we get into user interaction, and writing programs that actually serve a purpose. Can't wait!</p>
+ <p>Thanks to all,</p>
+ <p>sthurlow.com</p>
+ </section>
+ </content>
+</lesson>
+</document>
419 lesson05/index.htm
@@ -0,0 +1,419 @@
+<html>
+<head>
+<title>Lesson 5 - Functions</title>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
+<meta name="keywords" content="civilization,civ2,civ3,civ4,civilization iii,civilization ii,civilization iv,mod,python,xml,script,install" />
+<meta name="description" content="A Python and XML tutorial aimed at Civilization IV modding" />
+</head><link rel="stylesheet" type="text/css" href="../../stylesheet.css" />
+
+<body bgcolor="Teal">
+<div align="center" class="SidePanel">
+<div align="left" class="PaddingBig">
+<div class="MenuSection">
+<h1>Sthurlow.com</h1>
+<h2>Civilization IV Python tutorial</h2><h3>The Python Tutorial</h3>
+<p>The original sthurlow.com python tutorial</p>
+<p>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson01/">Installing Python</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson02/">Very Simple Programs</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson03/">Variables, Scripts</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson04/">Loops, Conditionals</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson05/">Functions</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson06/">Tuples, Lists, Dictionaries</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson07/">for Loop</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson08/">Classes</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson09/">Importing Modules</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson10/">File I/O</a></div>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/python/lesson11/">Error Handling</a></div>
+</p>
+<h3>The Civ4 Programming Tutorial</h3>
+<p>All new Civ4 programming tutorial</p>
+<p>
+<div class="MenuItem">&nbsp;<a href="http://www.sthurlow.com/">Lesson 1 (not released)</a></div>
+</p>
+<br /><br /></div></div>
+</div>
+
+<div align="center" class="TextPanel">
+<div align="left" class="Padding"><h2>Functions</h2>
+
+<h3>Introduction</h3>
+<p>Last lesson I said that we would delve into purposefull programming. That involves user input, and user input requires a thing called functions.</p>
+<p>What are functions? Well, in effect, functions are little self-contained programs that perform a specific task, which you can incorporate into your own, larger programs. After you have created a function, you can use it at any time, in any place. This saves you the time and effort of having to retell the computer what to do every time it does a common task, for example getting the user to type something in.</p>
+
+<h3>Using a function</h3>
+<p>Python has lots of pre-made functions, that you can use right now, simply by 'calling' them. 'Calling' a function involves you giving a function input, and it will return a value (like a variable would) as output. Don't understand? Here is the general form that calling a function takes:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 1 - How to call a function</div>
+<div align="left" class="CodeBody">
+<pre>
+function_name(parameters)
+</pre>
+</div>
+</div><p>See? Easy.</p>
+
+<ul><li>Function_name identifies which function it is you want to use (You'd figure...). For example, the function raw_input, which will be the first function that we will use.</li>
+<li>Parameters are the values you pass to the function to tell it what is should do, and how to do it.. for example, if a function multiplied any given number by five, the stuff in parameters tells the function which number it should multiply by five. Put the number 70 into parameters, and the function will do 70 x 5.</li>
+
+</ul>
+<h3>Parameters and Returned Values - Communicating with Functions</h3>
+<p>Well, that's all well and good that the program can multiply a number by five, but what does it have to show for it? A warm fuzzy feeling? Your program needs to see the results of what happened, to see what 70 x 5 is, or to see if there is a problem somewhere (like you gave it a letter instead of a number). So how does a function show what is does?</p>
+<p>Well, in effect, when a computer runs a function, it doesn't actually see the function name, but the result of what the function did. Variables do the exact same thing - the computer doesn't see the variable name, it sees the value that the variable holds. Lets call this program that multiplied any number by five, multiply(). You put the number you want multiplied in the brackets. So if you typed this:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 2 - Using a function</div>
+<div align="left" class="CodeBody">
+<pre>
+a = multiply(70)
+</pre>
+</div>
+</div><p>The computer would actually see this:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 3 - What the computer sees</div>
+<div align="left" class="CodeBody">
+<pre>
+a = 350
+</pre>
+</div>
+</div><p>note: don't bother typing in this code - multiply() isn't a real function, unless you create it.</p>
+<p>The function ran itself, then returned a number to the main program, based on what parameters it was given.</p>
+<p>Now let's try this with a real function, and see what it does. The function is called raw_input, and asks the user to type in something. It then turns it into a string of text. Try the code below:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 4 - Using raw_input</div>
+<div align="left" class="CodeBody">
+<pre>
+# this line makes 'a' equal to whatever you type in
+a = raw_input("Type in something, and it will be repeated on screen:")
+# this line prints what 'a' is now worth
+print a
+</pre>
+</div>
+</div><p>Say in the above program, you typed in 'hello' when it asked you to type something in. To the computer, this program would look like this:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 5 - What the computer sees</div>
+<div align="left" class="CodeBody">
+<pre>
+a = "hello"
+print "hello"
+</pre>
+</div>
+</div><p>Remember, a variable is just a stored value. To the computer, the variable 'a' doesn't look like 'a' - it looks like the value that is stored inside it. Functions are similar - to the main program (that is, the program that is running the function), they look like the value of what they give in return of running.</p>
+
+<h3>A Calculator Program</h3>
+<p>Lets write another program, that will act as a calculator. This time it will do something more adventerous than what we have done before. There will be a menu, that will ask you whether you want to multiply two numbers together, add two numbers together, divide one number by another, or subtract one number from another. Only problem - the raw_input function returns what you type in as a string - we want the number 1, not the letter 1 (and yes, in python, there is a difference.).</p>
+<p>Luckily, somebody wrote the function input, which returns what you typed in, to the main program - but this time, it puts it in as a number. If you type an integer (a whole number), what comes out of input is an integer. And if you put that integer into a variable, the variable will be an integer-type variable, which means you can add and subtract, etc.</p>
+<p>Now, lets design this calculator properly. We want a menu that is returned to every time you finish adding, subtracting, etc. In other words, to loop (HINT!!!) while (BIG HINT!!!) you tell it the program should still run.</p>
+<p>We want it to do an option in the menu if you type in that number. That involves you typing in a number (a.k.a input) and an if loop.</p>
+<p>Lets write it out in understandable English first:</p>
+
+<div align="center">
+<div align="center" class="CodeTitle">Code Example 6 - human-language example</div>
+<div align="left" class="CodeBody">
+<pre>
+START PROGRAM
+print opening message
+
+while we let the program run, do this:
+ #Print what options you have
+ print Option 1 - add
+ print Option 2 - subtract
+ print Option 3 - multiply
+ print Option 4 - divide
+ print Option 5 - quit program
+
+ ask for which option is is you want
+ if it is option 1:
+ ask for first number
+ ask for second number
+ add them together
+ print the result onscreen
+ if it is option 2:
+ ask for first number
+ ask for second number
+ subtract one from the other
+ print the result onscreen
+ if it is option 3:
+ ask for first number
+ ask for second number
+ multiply!
+ print the result onscreen
+ if it is option 4:
+ ask for first number
+ ask for second number
+ divide one by the other
+ print the result onscreen
+ if it is option 5: