text:
Civ/Sid Meier's Alpha Centauri/Early Game Strategy

Economics
The very heart and soul of any empire is the economy. It supersedes the army, and even technological research and innovation. Do not misunderstand this. The production of war materials and research are vitally important to your survival and eventual dominance, but an empire's ability to produce quantities of either is driven by the force and stability of that empire's economy. You must understand that players who use a strictly militaristic focus are playing the game from the "Momentum" standpoint. Their key hope is that their program of relentless assault can end the game before some Builder or Hybrid player can build up a strong enough economy to stand against them. Never forget:

 * 1) Your economy is the most versatile tool you have. In times of crisis, you can configure it to crank out massive amounts of cash to fund your war effort (or whatever), and in times of peace you can ratchet your research up through the roof.
 * 2) Contrast that to military units, which are actually only useful in three very specific situations: If you are attacked, if you launch an attack, or if you can make your opponent believe you are about to launch an attack (i.e. feint) (see below on creating turn advantage). Otherwise, they simply take up space on the board. They represent a certain amount of "potential energy." That is to say, the potential to cause harm to another empire or to defend your holdings.
 * 3) Technological advances are likewise "potential energy." By themselves they do nothing for you. You have to actually build something to get anything useful out of them (a new prototype, base facility, secret project...something).

Factors of production on Chiron
You've already been introduced to them, and here they are again, this time, with a slightly different treatment:

Nutrients: Enables your population to expand.

Minerals: Allows you to build stuff.

Energy: Drives your research efforts and puts cash in your pocket. In order to build a healthy economy, attention must be paid to all three.

Your economy is driven by the function of the passage of time acting against the three factors of production listed above. It's like plate tectonics, with time on one side and your productive factors on the other. You can vary your economy's effectiveness versus time (bigger or smaller "quakes" = speeding up or slowing down) by adjusting your three factors of production.

Basic economic theory
The basics of economic theory are intuitive, but are outlined below:

Makin' Big Cities: Maximize nutrient output over time. Note that without controls on growth (i.e., sufficient mineral production to produce anti-drone facilities), your base will suffer chronic rioting.

Makin' Productive Cities: Maximize mineral output over time. Lets you build stuff very quickly. Too much mineral production leads to eco-damage, which in turn, leads to "worm rape" — something you don't want to see.

Makin' Bill Gates Cities (lots of tech and cash): Maximize energy output over time. Generates money and research points very quickly, but comes with the ill effect that it takes a long time to build all the base facilities you need to get to this point (i.e., it will take even longer if you don't balance this with mineral production).

Intermediate economic theory
As I said above, basic management of the factors of productive is intuitive (if you want the base to grow, give them lots of food), but since it is clear that taking any of the factors of production to their extreme is probably detrimental in some way (to say nothing of the inefficiency it creates), it becomes obvious that some balance needs to be struck. He who has a clearer understanding of when to focus on which of the factors of production will almost always be able to create a stronger economy than he who is content to let the computer make production decisions.

Energy production is basically unimportant in the early game. You are starting from scratch. You have nothing. No infrastructure at all. What you need is a good balance of nutrients (to grow your population pretty rapidly), and minerals (to build your first, most basic facilities fairly quickly). Only when that has been accomplished should you begin to worry much over energy production or enhancement. For this reason, planting forests is probably the most important early-game terrain enhancing you can do. Due to mineral and energy restrictions, early forests will produce as much as early mines (and mines take 6-8 turns to build). Two forests (which tend to expand on their own), or one mine? You don't have to be a student of economics to see which is more efficient, and efficiency is the name of the game (and this provides something in the way of a specific explanation of the terraforming choices mentioned earlier in this guide). Of course, in the same breath, do not discount the value of mines and boreholes. Your spare formers should be working on both of these terrain enhancements as soon as you are able, planning for the day when the mineral restrictions come off, and enabling you to instantly shift your supply crawlers around to take advantage of new efficiencies brought about by your increasing tech-level.

Once you get your most essential base facilities constructed you should probably shift into a more balanced mineral/nutrient mix (still not paying terribly much attention to energy) in order to facilitate population growth, while using your selected "focus" to heighten each base's per turn output of one of the factors of production in particular. Here though, certain base facilities can make this more efficient (don't kick up your nutrient harvesting until you finish your Children's Creche, otherwise you're just spinning your wheels). Also, monitor your growth constantly as your bases creep up on their maximum size, and adjust your nutrient output accordingly. You don't want any wasted effort if you can help it. Wasted effort and resource is an opportunity for your opponent to close the gap on you and possibly overtake you.

Secret projects
A number of truly powerful Secret Projects become available amazingly early on in the game, and we'll take a brief look at each of them in turn. Evaluate them against your favored strategy and see which of them fit best with your game. When you have a list of projects that are "essential" to your strategy, pursue them with a vengeance in your games! Understand though (especially in multiplayer games) that you might not get all of the projects you'd like, so the important thing here is not to overcommit. That is to say, if there are currently six Secret Projects available to you, don't start working on all six at once! If you do, and someone beats you to a project, you are stuck with two options, neither of them very good. You can either opt to change the production in your base, losing half of the accumulated minerals you had built up toward that project, or you can have that base continue to build, with plans to switch over to a new project as soon as you get a tech that grants you one. The problem here though, is if you do that, you effectively tie that base up for a number of turns where no further developmental work can be accomplished at that base — not a good thing at all. So, take your project work in small slices, and try to only start a project when you are reasonably sure you can finish it ahead of everyone else.

The very best way to rapidly complete a secret project is to have all the bases in the immediate vicinity of the "Project Base" build Supply Crawlers and have them start harvesting minerals. In all likelihood, you will begin to run some eco-damage, but don't worry, it won't be for long! Remember that each crawler you have costs you a base of 30 minerals. Remember too, that most of the early game projects cost between 200-300 minerals, which means that for a paltry ten crawlers (less than that, in practice), you can complete any of the early game projects! This is one reason why Industrial Automation is so important. Your goal here is to keep building crawlers at an ever increasing rate until you have enough to send them all to the "Project Base" and finish the project. Alternately, you could simply set your nearby bases to building crawlers and shuffle them into the Project base upon completion, but this is slightly less efficient, although the upshot is that you don't have to worry with eco-damage creating fungal blooms and the potential for worm-rape. Also note that, if you have the cash, you can get significantly more "bang for your buck" by spending some cash to upgrade the crawler to a more expensive variant, because when you cash the crawler in toward the Secret Project, you will get its full mineral value; note however that crawler-upgrading is regarded as a cheat in many circles, so check beforehand to make sure that's acceptable, and if not, just use "regular" Crawlers as described above.

''This information was originally written by Velociryx in his SMAC FAQ. Used with permission.''


text: Template:Genealogy/WSToc

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

title: Template:Genealogy/WSToc


text:
Robotics/Stepper Motors

Stepper Motor Basics

 * Degree of Rotation - Every stepper motor has a degree of rotation. This value indicates how far the rotor will spin around its axis for each signal sent.

 * Number of Coil - These motors drive coils in a pattern to advance the rotor position

 * Driving a Coil - This is done by passing current through the coil. In stepper motors, all coils must be driven in both directions over a complete revolution.

 * Sequencing - These motors require the electronic control to change which coil in being driven at the correct time. Without this the motor will hold in one position.

 * H-Bridge Style Driver - ...

What's a stepper motor?

In robotics stepper motors are primarily used in stationary robots as they tend to consume quite a lot of power. They are ideal for movements that have to be accurate and are larger than 180°.

Common Uses/Part Sources

 * Floppy, hard disk, or CD/DVD-ROM drives - The heart of most these is the stepper motor. In most of these drives, there are two stepper motors. They position the read/write heads and they spin the medium.
 * Printers, scanners, plotters, and copy machines - Most of these devices utilize stepper motors. They are used primarily to position the print head or optics on an (X,Y) coordinate system. One motor positions on the X axis and the other positions on the Y axis.
 * CNC machines, routers, scanners, lathes etc - Used for X/Y/Z positioning of heads.

title: Robotics/Stepper Motors


text:
Quantum Mechanics/Symmetry and Quantum Mechanics

The idea of symmetry plays a huge role in physics. We have already used symmetry arguments in the theory of relativity -- applying the principle of relativity to obtain the dispersion relation for relativistic matter waves is just such an argument. In this section we begin to explore how symmetry can be used to increase our understanding of quantum mechanics.

Free Particle
The wave function for a free particle of definite momentum, P, and energy, E is given by

 * $$\psi = \exp i(kx-\omega t) = \exp i \frac{Px - Et}{\hbar} $$

For this wave function |ψ|²=1 everywhere, so the probability of finding the particle anywhere in space and time is uniform - just like the particle energy.

This contrasts with the probability distribution which arises if we assume a free particle to have the wave function

 * $$\psi = \sin \frac{Px - Et}{\hbar}

\quad |\psi|^2= \sin^2 \frac{Px - Et}{\hbar}$$

In this case the probability varies with position and time, which is inconsistent with a uniform probability distribution. This solution is less symmetric than the problem.

Symmetry and Definiteness
Quantum mechanics is a probabilistic theory, in the sense that the predictions it makes tell us, for instance, the probability of finding a particle somewhere in space. If we know nothing about a particle's previous history, and if there are no physical constraints that would make it more likely for a particle to be at one point along the axis than any another, then the probability distribution must be P(x)=constant.

This is an example of a symmetry argument. Expressed more formally, it states that if the above conditions apply, then the probability distribution ought to be subject to the condition P(x+d)=P(x) for any constant value of d. This can only be true if P(x) is a constant.

In the language of physics, if there is nothing that gives the particle a higher probability of being at one point rather than another, then the probability is independent of position and the system is invariant under displacement in the direction.

The above argument doesn't suffice for quantum mechanics, since as we have learned, the fundamental quantity describing a particle is not the probability distribution, but the wave function. Thus, the wave function rather than the probability distribution ought to be the quantity which is invariant under displacement.

This condition turns out to be too restrictive, because it implies that ψ is constant but we know that a one-dimensional plane wave, which describes a particle with a uniform probability of being found anywhere along the axis, has the form

 * $$\psi = \exp ikx \,$$

(For simplicity we temporarily ignore the time dependence.) If we make the substitution x→x+d in a plane wave, we get

 * $$\psi = \exp ik(x+d) = \exp ikd \exp ikx \,$$

The wave function is thus technically not invariant under displacement, in that the displaced wave function is multiplied by the factor exp(ikd). However, the probability distribution of the displaced wave function still equals one everywhere, so there is no change in what we observe.

Thus, in determining invariance under displacement, we are allowed to ignore changes in the wave function which consist only of multiplying it by a complex constant with an absolute value of one; i.e one of the form exp(iα) with α real. Such a multiplicative constant is called a phase factor, and α the phase.

It is easy to convince oneself by trial and error or by more sophisticated means that the only form of wave function which satisfies this condition is

 * $$\psi = A \exp ikx \,$$

where A is a (possibly complex) constant. This is just in the form of a complex exponential plane wave with wavenumber k. Thus, not only is the complex exponential wave function invariant under displacements in the manner defined above, it is the only wave function which is invariant to displacements. Furthermore, the phase factor which appears for a displacement d of such a plane wave takes the form exp(ikd), where k is the wavenumber of the plane wave.

As an example, let us see if a wave packet is invariant under displacement. Let's define a wave packet consisting of two plane waves:
 * $$\psi = e^{ik_1 x} + e^{ik_2 x} $$

Making the substitution x→x+d in this case results in
 * $$\begin{matrix}

\psi & = & e^{ik_1 (x+d)} + e^{ik_2 (x+d)} \\ & = & e^{ik_1 d}e^{ik_1 x} + e^{ik_2 d}e^{ik_2 x} \\ & \ne & \left[ e^{ik_1 (x+d)} + e^{ik_2 (x+d)} \right] e^{i\alpha} \end{matrix}$$ no matter what value α has.

The impossibility of writing the displaced wavefunction as the original multiplied by a phase factor lends plausibility to the assertion that a single complex exponential is the only possible form of the wave function that is invariant under displacement.

Notice that the wave packet does not have definite wavenumber, and hence, momentum. In particular, non-zero amplitudes exist for the associated particle to have either momentum $$\hbar k_1$$ or $$\hbar k_2$$. This makes sense from the point of view of the uncertainty principle -- for a single plane wave the uncertainty in position is complete and the uncertainty in momentum is zero. For a wave packet the uncertainty in position is reduced and the uncertainty in the momentum is non-zero.

However, we see that this idea can be carried further: A definite value of momentum must be associated with a completely indefinite probability distribution in position. This corresponds to a wave function which has the form of a complex exponential plane wave.

However, such a plane wave is invariant under a displacement d, except for the multiplicative phase factor, which has no physical consequences since it disappears when the probability distribution is obtained. Thus, we see that invariance under displacement of the wave function and a definite value of the momentum are linked, in that each implies the other:

 * Invariance under displacement ⇔ Definite momentum

We can compare this with classical mechanics, where we saw that if the energy is invariant under displacement then momentum is conserved, and similarly for generalised coordinates.

The above equivalence can also be extended to arbitary coordinates.

In particular, since the time dependence of a complex exponential plane wave is

 * $$e^{-i\omega t} = e^{-i \frac{Et}{\hbar}}$$

we have by analogy with the above argument that
 * Invariance under time shift ⇔ Definite energy

Thus, invariance of the wave function under a displacement in time implies a definite value of the energy of the associated particle.

Another useful instance of this is

 * Invariance under rotation ⇔ Definite angular momentum

since the same connection between rotation and angular momentum holds as in classical mechanics.

In the previous chapter we assumed that the frequency (and hence the energy) was definite and constant for a particle passing through a region of variable potential energy. We now see that this assumption is justified only if the potential energy doesn't change with time. This is because a time-varying potential energy eliminates the possibility of invariance under time shift.

Compatible Variables
We already know that definite values of certain pairs of variables cannot be obtained simultaneously in quantum mechanics. For instance, the indefiniteness of position and momentum are related by the uncertainty principle -- a definite value of position implies an indefinite value of the momentum and vice versa. If definite values of two variables can be simultaneously obtained, then we call these variables compatible. If not, the variables are incompatible.

If the wave function of a particle is invariant under the transformations associated with both variables, then the variables are compatible. For instance, the complex exponential plane wave associated with a free particle is invariant under displacements in both space and time. Since momentum is associated with space displacements and energy with time displacements, the momentum and energy are compatible variables for a free particle.

Compatibility and Conservation
Variables which are compatible with the energy have a special status. The wave function which corresponds to a definite value of such a variable is invariant to displacements in time. Thus, if the wave function is also invariant to some other transformation at a particular time, it is invariant to that transformation for all time. The variable associated with that transformation thus retains its definite value for all time -- i. e., it is conserved.

For example, the complex exponential plane wave implies a definite value of energy, and is thus invariant under time displacements. At time ''t'=0, it is also invariant under displacements, which corresponds to the fact that it represents a particle with a known value of momentum. However, since momentum and energy are compatible for a free particle, the wave function will represent the same value of momentum at all other times.

In other words, if the momentum is definite at t=0, it will be definite at all later times, and furthermore will have the same value. This is how the conservation of momentum (and by extension, the conservation of any other variable compatible with energy) is expressed in quantum mechanics.

We will see later how to describe this in terms of operators.


text:
Genealogy/LDS

The Church of Jesus Christ of Latter-Day Saints has many, many genealogy resourcs. The church is in fact on the forefront when it comes to genealogical research, because of their beliefs in proxy, postmortem baptism and ordinances. Members of the church and those who work in the centers they run are extremely helpful to the genealogical community at large; almost every genealogist has come into contact with a member of the church one way or another.

Personal Ancestral File (PAF)
The Church of Jesus Christ of Latter-Day Saints (Mormons) has in the past offered a computer program for organization of genealogical records, but the program is no longer being offered or supported.

to be written: usage guide, etc.

FamilySearch.org
[FamilySearch.Net] domain was donated to the church by an individual who refused a large amount of money offered by a private interest. The church now maintains familysearch.org for the use of family history enthusiasts. The database of records on this site is derived from the Ancestral File (AF) project of the LDS Family History Department and from other sources. AF started as a collection of "4-generation" genealogical submissions from members of the LDS Church, but has grown substantially since the early 1980's when the project originally started. Many genealogy archivists and Family History Library patrons have contributed data to the collection. The total number of individuals listed in the database numbers in the millions.

The quality of the information varies considerably within the database, as both professionals and amateurs participated in the submission of data. For some individuals the data is very well documented, and links to original records can be obtained. Some data is obviously of poor quality, with perhaps incorrect genders or with the same child listed 4 or 5 times, or having other obvious errors. Another problem with this database was the method used to match up comparable records, which was done "automagically", or in other words, through a completely automated process. When matching individuals with substantial amounts of accurate information (full birth date, place information, death dates, etc.), this works fairly smoothly, but a user can sometimes spot a situation in which a family line moves from one submission to another and has been patched together.

The worst situations occur when there is a "flame war" going on between different branches of a family arguing over what the correct information should be on a common ancestor. To the credit of the Family History Library, there is a dispute resolution procedure to try and clean up messes of this nature, but it does require formal documentation in the form of birth certificates, wills, etc., that are not normally required for ordinary submissions.

If a user spots errors, there are procedures to try and clean up the database, but it is somewhat bureaucratic to get through. It is still worth doing if you are cleaning up your own family lines.

You can easily access this website and search its large database of records, and even download some of it as a GEDCOM for inclusion in whatever genealogy software you prefer that supports the GEDCOM format (it's the de facto exchange format between genealogy programs)

to be written: exploring the site, etc.

title: Genealogy/LDS


text:
Physics Study Guide/Thermodynamics

=Introduction= Thermodynamics deals with the movement of heat and its conversion to mechanical and electrical energy among others.

=Laws of Thermodynamics=

First Law
The First Law is a statement of conservation of energy law:

The First Law can be expressed as the change in internal energy of a system ($$\Delta U$$) equals the amount of energy added to a system (Q), such as heat, minus the work expended by the system on its surroundings (W).

If Q is positive, the system has gained energy (by heating).

If W is positive, the system has lost energy from doing work on its surroundings.

As written the equations have a problem in that neither Q or W are state functions or quantities which can be known by direct measurement without knowing the history of the system.

In a gas, the first law can be written in terms of state functions as

Zero-th Law
After the first law of Thermodynamics had been named, physicists realised that there was another more fundamental law, which they termed the 'zero-th'.

This is that:

An alternate form of the 'zero-th' law can be described:

This second statement, in turn, gives rise to a definition of Temperature (T):

Second Law
This law states that heat will never flow from a cold object to a hot object.

$$ S = k_B \cdot ln(\Omega) $$

where $$k_B$$ is the Boltzmann constant ($$k_B = 1.380658 \cdot 10^{-23} \mbox{ kg m}^2 \mbox{ s}^{-2} \mbox{ K}^{-1}$$) and $$\Omega$$ is the partition function, i. e. the number of all possible states in the system.

This was the statistical definition of entropy, there is also a "macroscopic" definition:

$$ S = \int \frac{\mathrm{d}Q}{T} $$

where T is the temperature and dQ is the increment in energy of the system.

Third Law
The third law states that a temperature of absolute zero cannot be reached.

=Temperature Scales=

There are several different scales used to measure temperature. Those you will most often come across in physics are degrees Celsius and kelvins.

Celsius temperatures use the symbol Θ. The symbol for degrees Celsius is °C. Kelvin temperatures use the symbol T. The symbol for kelvins is K.

The Celsius Scale
The Celsius scale is based on the melting and boiling points of water.

The temperature for freezing water is 0 °C. This is called the freezing point

The temperature of boiling water is 100 °C. This is called the steam point.

The Celsius scale is sometimes known as 'Centigrade', but the CGPM chose degrees Celsius from among the three names then in use way back in 1948, and centesimal and centigrade should no longer be used. See Wikipedia for more details.

The Kelvin Scale
The Kelvin scale is based on a more fundamental temperature than the melting point of ice. This is absolute zero (equivalent to −273.15 °C), the lowest possible temperature anything could be cooled to—where the kinetic energy of any system is at its minimum. The Kelvin scale was developed from an observation on how the pressure and volume of a sample of gas changes with temperature-  PV/T   is  a constant. If the temperature ( T)was reduced, then the pressure ( P) exerted by Volume (V) the Gas would also reduce, in direct proportion. This is a simple experiment and can be carried out in most school labs. Gases were assumed to  exert no pressure  at  -273 degree Celsius. ( In fact all gases will have condensed into liquids or solids at a somewhat higher temperature)

Although the Kelvin scale starts at a different point to Celsius, its units are of exactly the same size.

Therefore:

=Specific Latent Heat=

Energy is needed to break bonds when a substance changes state. This energy is sometimes called the latent heat. Temperature remains constant during changes of state.

To calculate the energy needed for a change of state, the following equation is used:

The specific latent heat, L, is the energy needed to change the state of 1 kg of the substance without changing the temperature.

The latent heat of fusion refers to melting. The latent heat of vapourisation refers to boiling.

=Specific Heat Capacity=

The specific heat capacity is the energy needed to raise the temperature of a given mass by a certain temperature.

The change in temperature of a substance being heated or cooled depends on the mass of the substance and on how much energy is put in. However, it also depends on the properties of that given substance. How this affects temperature variation is expressed by the substance's specific heat capacity (c). This is measured in J/(kg·K) in SI units.

title: Physics Study Guide/Thermodynamics


text:
User:Perl~enwikibooks/Ellen Foster

 * User:Perl/Ellen Foster/character
 * User:Perl/Ellen Foster/art
 * User:Perl/Ellen Foster/themes
 * User:Perl/Ellen Foster/poem
 * User:Perl/Ellen Foster/timeline
 * User:Perl/Ellen Foster/quotes

title: User:Perl~enwikibooks/Ellen Foster


text:
User:Perl~enwikibooks/Ellen Foster/character

Ellen's mama's mama is an extremely bitter woman who treats Ellen with undue contempt. Ellen's mama's mama resents Ellen and blames her for Ellen's dad's mistakes (most notably Ellen's mother's death). Ellen has trouble understanding why her grandmother is unable to differentiate Ellen from Ellen's father.

Ellen's father is a lazy and dirty man who thinks of only himself. He usually isn't around, and when he is around he is usually drunk and prone to sexually harassing Ellen. As a result, Ellen is forced to take care of the bills and make dinner for herself and her father. Ellen talks about wanting to kill her father.

Starletta and her family are very poor. Ellen informs the reader that Starletta has been known to eat dirt and is slightly retarded. Their family, however, is kind and generous to Ellen. They feed her and let her stay with them without asking any questions. Thus, Starletta becomes Ellen's best friend. At first, Ellen has mixed feelings towards the family because they are "colored," but near the end of the novel, Ellen realizes that this was a silly opinion to hold and she apologizes to Starletta.

Mama (Ellen’s mother) dies very early in Ellen’s life from an overdose of medications. Ellen’s father refuses to take her mother to the hospital making the death partly his fault. When Ellen goes to her grandmother’s house, the reader learns that Mama was very highly regarded by her family. It is not clear, however, why Ellen’s mother married the man that she did instead of pursuing a career.

Dora and Nadine are a fairly wealthy family who allow Ellen to stay at their house for Christmas. When Dora (Nadine's daughter) asks Ellen what she wants for Christmas, Ellen says that she only wants paper, although she hopes that Dora will get her something better. Dora only gives Ellen paper and Ellen gets upset. Ellen gives Dora a hand drawn painting, for which Dora expresses dislike. Ellen becomes insulted by this and by the fact that Dora was so sparing when she shopped for a present.

<< | >>


text:
Non-Programmer's Tutorial for Python 2.6/Front matter

Python 3 notice: it's not recommended to learn Python 2 since it has been deprecated and replaced by Python 3. If you're new to Python, start learning Python 3. There's a Python 3 version of this Wikibook.

All example Python source code in this tutorial is granted to the public domain. Therefore, you may modify it and relicense it under any license you please. Since you are expected to learn programming, the GNU Free Documentation License would require you to keep all programs that are derived from the source code in this tutorial under that license. Since the python source code is granted to the public domain, that requirement is waived.

This tutorial was originally written in LaTeX and was available at: http://www.honors.montana.edu/~jjc/easytut/. It was moved here because the other server is going away and it was being read at least ten times a day. This document is available as LaTeX, HTML, PDF, and Postscript. Go to http://jjc.freeshell.org/easytut/ (Also could try http://web.archive.org/web/*/http://www.honors.montana.edu/~jjc/easytut/ or http://www.geocities.com/jrincayc/easytut.tar.gz ) to see all these forms. There are also versions of this in Korean, Spanish, Italian and Greek in the tar file.

The Non-Programmers' Tutorial For Python is a tutorial designed to be an introduction to the Python programming language. This guide is for someone with no programming experience.

If you have programmed in other languages I recommend using Python Tutorial for Programmers written by Guido van Rossum.

If you have any questions or comments please use the discussion pages or see ../Authors for author contact information. I welcome questions and comments about this tutorial. I will try to answer any questions you have as best I can.

Thanks go to James A. Brown for writing most of the Windows install info. Thanks also to Elizabeth Cogliati for complaining enough : about the original tutorial (that is almost unusable for a non-programmer), for proofreading, and for many ideas and comments on it. Thanks to Joe Oppegaard for writing almost all the exercises. Thanks to everyone I have missed.

Other resources
See also chapter The End for some more comments.
 * Python Home Page
 * Python Documentation
 * Python Tutorial for Programmers
 * LaTeX, PDF, and Postscript, and Zip versions


text:
Non-Programmer's Tutorial for Python 2.6/Intro

First things first
So, you've never programmed before. As we go through this tutorial, I will attempt to teach you how to program. There really is only one way to learn to program.  You must read code and write code (as computer programs are often called). I'm going to show you lots of code. You should type in code that I show you to see what happens. Play around with it and make changes. The worst that can happen is that it won't work. When I type in code it will be formatted like this:

That's so it is easy to distinguish from the other text. If you're reading this on the web, you'll notice the code is in color -- that's just to make it stand out, and to make the different parts of the code stand out from each other. The code you enter will probably not be colored, or the colors may be different, but it won't affect the code as long as you enter it the same way as it's printed here.

If the computer prints something out it will be formatted like this:

Hello, World!

(Note that printed text goes to your screen, and does not involve paper. Before computers had screens, the output of computer programs would be printed on paper.)

If you try this program out and you get a syntax error, check and see what version of python you have. If you have python 3.0, you should be using the Non-Programmer's Tutorial for Python 3.0. This article was made for Python 2.6

There will often be a mixture of the text you type (which is shown in bold) and the text the program prints to the screen, which would look like this:

Halt! Who Goes there? Josh You may pass, Josh

(Some of the tutorial has not been converted to this format. Since this is a wiki, you can convert it when you find it.)

I will also introduce you to the terminology of programming - for example, that programming is often referred to as coding. This will not only help you understand what programmers are talking about, but also help the learning process.

Now, on to more important things. In order to program in Python you need the Python software. If you don't already have the Python software go to http://www.python.org/download/ and get the proper version for your platform. Download it, read the instructions and get it installed.

Installing Python
For Python programming you need a working Python installation and a text editor. Python comes with its own editor IDLE, which is quite nice and totally sufficient for the beginning. As you get more into programming, you will probably switch to some other editor like emacs, vi or another.

The Python download page is http://www.python.org/download. The most recent version is 3.1, but any Python 2.x version since 2.2 will work for this tutorial. Be careful with the upcoming Python 3, though, as some major details will change and break this tutorial's examples. A version of this tutorial for Python 3 is at Non-Programmer's Tutorial for Python 3. There are various different installation files for different computer platforms available on the download site. Here are some specific instructions for the most common operating systems:

Linux, BSD and Unix users
You are probably lucky and Python is already installed on your machine. To test it type python on a command line. If you see something like that in the following section, you are set.

If you have to install Python, just use the operating system's package manager or go to the repository where your packages are available and get Python. Alternatively, you can compile Python from scratch after downloading the source code. If you get the source code make sure you compile in the Tk extension if you want to use IDLE.

Mac users
Starting from Mac OS X (Tiger), Python ships by default with the operating system, but you might want to update to the newer version (check the version by starting python in a command line terminal). Also IDLE (the Python editor) might be missing in the standard installation. If you want to (re-)install Python, have a look at the Mac page on the Python download site.

Windows users
Some computer manufacturers pre-install Python. To check if you already have it installed, open command prompt (cmd in run menu) or MS-DOS and type python. If it says "Bad command or file name" you will need to download the appropriate Windows installer (the normal one, if you do not have a 64-bit AMD or Intel chip). Start the installer by double-clicking it and follow the procedure. Python for windows can be downloaded from the official site of python

Interactive Mode
Go into IDLE (also called the Python GUI). You should see a window that has some text like this: Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information.

****************************************************************  Personal firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is not visible on any external interface and no data is sent to or received from the Internet. ****************************************************************

IDLE 1.2.1 >>> The  is Python's way of telling you that you are in interactive mode. In interactive mode what you type is immediately run. Try typing  in. Python will respond with. Interactive mode allows you to test out and see what Python will do. If you ever feel you need to play with new Python statements, go into interactive mode and try them out.

Creating and Running Programs
Go into IDLE if you are not already. In the menu at the top, select  then. In the new window that appears, type the following:

Now save the program: select  from the menu, then. Save it as " " (you can save it in any folder you want). Now that it is saved it can be run.

Next run the program by going to  then   (or if you have a older version of IDLE use   then  ). This will output  on the   window.

For a more in-depth introduction to IDLE, a longer tutorial with screenshots can be found at http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html

Running Python Programs in Unix
If you are using Unix (such as Linux, Mac OSX, or BSD), if you make the program executable with, and have as the first line: you can run the python program with  like any other command.

Note: In some computer environments, you need to write:

Example for Solaris:

Program file names
It is very useful to stick to some rules regarding the file names of Python programs. Otherwise some things might go wrong unexpectedly. These don't matter as much for programs, but you can have weird problems if you don't follow them for module names (modules will be discussed later).

 * 1) Always save the program with the extension .py. Do not put another dot somewhere else in the file name.
 * 2) Only use standard characters for file names: letters, numbers, dash (-) and underscore (_).
 * 3) White space (" ") should not be used at all (e.g. use underscores instead).
 * 4) Do not use anything other than a letter (particularly no numbers!) at the beginning of a file name.
 * 5) Do not use "non-english" characters (such as ä, ö, <tt>ü</tt>, <tt>å</tt> or <tt>ß</tt>) in your file names, or, even better, do not use them at all when programming.

Using Python from the command line
If you don't want to use Python from the command line, you don't have to, just use IDLE. To get into interactive mode just type  without any arguments. To run a program, create it with a text editor (Emacs has a good Python mode) and then run it with.

Additionally, to use Python within Vim, you may want to visit Using vim as a Python IDE

Where to get help
At some point in your Python career you will probably get stuck and have no clue about how to solve the problem you are supposed to work on. This tutorial only covers the basics of Python programming, but there is a lot of further information available.

Python documentation
First of all, Python is very well documented. There might even be copies of these documents on your computer, which came with your Python installation: * The official Python Tutorial by Guido van Rossum is often a good starting point for general questions.
 * For questions about standard modules (you will learn what this is later), the Python Library Reference is the place to look.
 * If you really want to get to know something about the details of the language, the Python Reference Manual is comprehensive but quite complex for beginners.

Python user community
There are a lot of other Python users out there, and usually they are nice and willing to help you. This very active user community is organised mostly through mailing lists and a newsgroup:
 * The tutor mailing list is for folks who want to ask questions regarding how to learn computer programming with the Python language.
 * The python-help mailing list is python.org's help desk. You can ask a group of knowledgeable volunteers questions about all your Python problems.
 * The Python newsgroup [news:comp.lang.python comp.lang.python] (Google groups archive) is the place for general Python discussions, questions and the central meeting point of the community.

In order not to reinvent the wheel and discuss the same questions again and again, people will appreciate very much if you do a web search for a solution to your problem before contacting these lists!


text:
Non-Programmer's Tutorial for Python 2.6/Hello, World

What you should know
You should know how to edit programs in a text editor or IDLE, save the file and run the file once the files have been saved to your disk.

Printing
Programming tutorials since the beginning of time have started with a little program called "Hello, World!" The syntax changed in Python 3.0. If you are using Python 3.0, you should be reading Non-Programmer's Tutorial for Python 3 instead. So here is the Python 2.6 example:

If you are using the command line to run programs then type it in with a text editor, save it as  and run it with

Otherwise go into IDLE, create a new window, and create the program as in section Creating and Running Programs.

When this program is run here's what it prints:

Hello, World!

Now I'm not going to tell you this every time, but when I show you a program I recommend that you type it in and run it. I learn better when I type it in and you probably do too.

Now here is a more complicated program:

When you run this program it prints out:

Jack and Jill went up a hill to fetch a pail of water; Jack fell down, and broke his crown, and Jill came tumbling after.

When the computer runs this program it first sees the line:

so the computer prints:

Jack and Jill went up a hill

Then the computer goes down to the next line and sees:

So the computer prints to the screen:

to fetch a pail of water;

The computer keeps looking at each line, follows the command and then goes on to the next line. The computer keeps running commands until it reaches the end of the program.

Terminology
Now is probably a good time to give you a bit of an explanation of what is happening - and a little bit of programming terminology.

What we were doing above was using a command called. The  command is followed by one or more arguments. So in this example

there is one argument, which is. Note that this argument is a group of characters enclosed in double quotes ("). This is commonly referred to as a string of characters, or string, for short.  Another example of a string is.

A command and its arguments are collectively referred to as a statement, so

is an example of a statement.

That's probably more than enough terminology for now.

Expressions
Here is another program:

And here is the output when the program is run:

2 + 2 is 4 3 * 4 is 12 100 - 1 is 99 (33 + 2) / 5 + 11.5 is 18.5

As you can see, Python can turn your six hundred dollar computer into a 2 dollar calculator.

In this example, the print command is followed by two arguments, with each of the arguments separated by a comma. So with the first line of the program

The first argument is the string  and the second argument is the mathematical expression , which is commonly referred to as an expression.

What is important to note is that a string is printed as is (the string is what is within the double quotes but doesn't include the double quotes themselves. So the string is printed without the enclosing double quotes.) But an expression is evaluated, (in other words, converted) to its actual value.

Python has six basic operations for numbers:

Notice that division follows the rule, if there are no decimals to start with, there will be no decimals to end with. The following program shows this:

With the output:

14 / 3 = 4 14 % 3 = 2 14.0 / 3.0 = 4.66666666667 14.0 % 3.0 = 2.0 14.0 / 3 = 4.66666666667 14.0 % 3 = 2.0 14 / 3.0 = 4.66666666667 14 % 3.0 = 2.0

Notice how Python gives different answers for some problems depending on whether or not decimal values are used.

The order of operations is the same as in math: So use parentheses to structure your formulas when needed.
 * parentheses
 * exponents
 * multiplication, division  , and remainder
 * addition  and subtraction

Talking to humans (and other intelligent beings)
Often in programming you are doing something complicated and may not in the future remember what you did. When this happens, the program should probably be commented. A comment is a note to you and other programmers explaining what is happening. For example:

Which outputs

3.14285714286

Notice that the comment starts with a hash:. Comments are used to communicate with others who read the program and your future self to make clear what is complicated.

Note that any text can follow a comment, and that when the program is run, the text after the  through to the end of that line is ignored. The  does not have to be at the beginning of a new line:

Examples
Each chapter (eventually) will contain examples of the programming features introduced in the chapter. You should at least look over them and see if you understand them. If you don't, you may want to type them in and see what happens. Mess around with them, change them and see what happens.

Denmark.py

Output:

Something's rotten in the state of Denmark. -- Shakespeare

School.py

Output:

First Grade 1 + 1 = 2 2 + 4 = 6 5 - 2 = 3 Third Grade 243 - 23 = 220 12 * 4 = 48 12 / 3 = 4 13 / 3 = 4 R 1 Junior High 123.56 - 62.12 = 61.44 (4 + 3) * 2 = 14 4 + 3 * 2 = 10 3 ** 2 = 9

Exercises

 * 1) Write a program that prints your full name and your birthday as separate strings.
 * 2) Write a program that shows the use of all 6 math functions.


text:
Non-Programmer's Tutorial for Python 2.6/Who Goes There?

Input and Variables
Now I feel it is time for a really complicated program. Here it is: (user response: using Linux and Geany editor...only option shown was 'user_return'...output was correct. However, when manually typed 'user_reply' also worked correctly, even though not displayed as a option in Geany...what is the functional difference between these two?)

When I ran it, here is what my screen showed:

Halt! Who goes there? Josh You may pass, Josh

Note: After running the code by pressing F5, the Python shell will only give the output:

Halt! Who goes there?

You need to enter your name in the Python shell, and then press Enter to get the rest of the output.

Of course when you run the program your screen will look different because of the  statement. When you ran the program you probably noticed (you did run the program, right?) that you had to type in your name and then press Enter. Then the program printed out some more text and also your name. This is an example of input. The program reaches a certain point and then waits for the user to input some data that the program can use later.

Of course, getting information from the user would be useless if we didn't have anywhere to put that information and this is where variables come in. In the previous program,  is a variable. Variables are like a box that can store some piece of data. Here is a program to show examples of variables:

And here is the output:

a + b is 555.4 first_name is Bill Sorted Parts, After Midnight or Spam

The variables in the above program are,  ,  ,  , and. A variable in Python can store any type of data - in this example we stored some strings (e.g. "Bill") and some numbers (e.g. 432).

Note the difference between strings and variable names. Strings are marked with quotation marks, which tells the computer "don't try to understand, just take this text as it is":

This would print the text:

first_name

as-is. Variable names are written without any quotation marks and instruct the computer "use the value I've previously stored under this name":

which would print (after the previous example):

Bill

Assignment
Okay, so we have these boxes called variables and also data that can go into the variable. The computer will see a line like  and it reads it as "Put the string   into the box (or variable)  ". Later on it sees the statement  and it reads it as "put the sum of   or   which equals   into  ". The right hand side of the statement is evaluated and the result is stored in the variable on the left hand side. This is called assignment, and you should not confuse the assignment equal sign with "equality" in a mathematical sense here (that's what   will be used for later).

Here is another example of variable usage:

And of course here is the output:

1 2 4

Even if it is the same variable on both sides the computer still reads it as "First find out the data to store and then find out where the data goes".

One more program before I end this chapter:

The output I got was:

Type in a Number: 12.34 Type in a String: Hello number = 12.34 number is a  number * 2 = 24.68 text = Hello text is a  text * 2 = HelloHello

Notice that  was gotten with   while   was gotten with. returns a string while  returns a number. When you want the user to type in a number use  but if you want the user to type in a string use.

The second half of the program uses  which tells what a variable is. Numbers are of type  or , which are short for integer and floating point (mostly used for decimal numbers), respectively. Text strings are of type, short for string. Integers and floats can be worked on by mathematical functions, strings cannot. Notice how when python multiplies a number by an integer the expected thing happens. However when a string is multiplied by an integer the result is that multiple copies of the string are produced (i.e., ).

The operations with strings do different things than operations with numbers. Here are some interactive mode examples to show that some more.

>>> "This" + " " + "is" + " joined." 'This is joined.' >>> "Ha, " * 5 'Ha, Ha, Ha, Ha, Ha, ' >>> "Ha, " * 5 + "ha!" 'Ha, Ha, Ha, Ha, Ha, ha!' >>>

This could also be done as a program:

Here is the list of some string operations:

Examples
Rate_times.py

Sample runs:

Input a rate and a distance Rate: 5 Distance: 10 Time: 2

Input a rate and a distance Rate: 3.52 Distance: 45.6 Time: 12.9545454545

Area.py

Sample runs:

Calculate information about a rectangle Length: 4 Width: 3 Area 12 Perimeter 14

Calculate information about a rectangle Length: 2.53 Width: 5.2 Area 13.156 Perimeter 15.46

temperature.py

Sample runs:

Fahrenheit temperature: 32 0.0

Fahrenheit temperature: -40 -40.0

Fahrenheit temperature: 212 100.0

Fahrenheit temperature: 98.6 37.0

Exercises

 * 1) Write a program that gets 2 string variables and 2 integer variables from the user, concatenates (joins them together with no spaces) and displays the strings, then multiplies the two numbers on a new line.


text:
Non-Programmer's Tutorial for Python 2.6/Count to 10

While loops
Here we present our first control structure. Ordinarily, the computer starts with the first line and then goes down from there. However, control structures change the order of how the statements are executed and/or decide if a certain statement(s) will be run. Here's the source for a program that uses the  control structure:

And here is the extremely exciting output:

1 2 3 4 5 6 7 8 9 10

And you thought it couldn't get any worse after turning your computer into a five dollar calculator?

So what does the program do? First, it sees the line  which tells the computer to sets   to the value of zero. Then, it sees  which tells the computer to check whether. The first time the computer sees this while statement,  is equal to zero, which means   is less than 10, so the computer proceeds to run the succeeding indented, or tabbed in, statements. After the last statement,, within this while "loop" is run, the computer goes back up again to the   to check the current value of. In other words, as long as  is less than ten, the computer will run the tabbed in statements. With  repeatedly adding one to , eventually the while loop makes   equal to ten, and makes the   no longer true. Reaching that point, the program will not run the indented lines any longer.

Always remember to put a colon ":" after the "while" statement!

Here is another example of the use of :

Enter Numbers to add to the sum. Enter 0 to quit. Current Sum: 0 Number? 200 Current Sum: 200 Number? -15.25 Current Sum: 184.75 Number? -151.85 Current Sum: 32.9 Number? 10.00 Current Sum: 42.9 Number? 0 Total Sum = 42.9

Notice how  is only run at the end. The  statement only affects the lines that are indented with whitespace. The  means "does not equal" so   means: "until   is zero, run the tabbed statements that follow."

Infinite loops
Now that we have while loops, it is possible to have programs that run forever. An easy way to do this is to write a program like this:

The "==" operator is used to test equality of the expressions on the two sides of the operator, just as "<" was used for "less than" before (you will get a complete list of all comparison operators in the next chapter).

This program will output  until the heat death of the universe or until you stop it, because 1 will forever be equal to 1. The way to stop it is to hit the Control (or Ctrl) button and C (the letter) at the same time. This will kill the program. (Note: sometimes you will have to hit enter after the Control-C.)

Examples
Fibonacci.py

Output:

0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181

Note the output on a single line by use of a comma at the end of the  statement.

Password.py

Sample run: Password: auo Password: y22 Password: password Password: open sesame Password: unicorn Welcome in

Exercises
Write a program that asks the user for a Login Name and password. Then when they type "lock", they need to type in their name and password to unlock the program.


text:
Non-Programmer's Tutorial for Python 2.6/Decisions

If statement
As always I believe I should start each chapter with a warm-up typing exercise, so here is a short program to compute the absolute value of a number:

Here is the output from the two times that I ran this program:

Type in a number: -14 The absolute value of -14 is: 14

Type in a number: 24 The absolute value of 24 is: 24

So what does the computer do when it sees this piece of code? First it prompts the user for a number with the statement " ". Next it reads the line " ". If  is less than zero Python runs the line " ". Otherwise it runs the line " ".

More formally Python looks at whether the expression  is true or false. An  statement is followed by an indented block of statements that are run when the expression is true. Optionally after the  statement is an   statement and another indented block of statements. This second block of statements is run if the expression is false.

There are a number of different tests that an expression can have. Here is a table of all of them:

Another feature of the  command is the   statement. It stands for else if and means if the original  statement is false but the   part is true, then do the   part. And if neither the  or   expressions are true, then do what's in the   block. Here's an example:

and the output:

1 <= 7 2 <= 7 3 <= 7 4 <= 7 5 <= 7 6 > 5 7 > 5 8 > 5 9 > 5 10 > 5

Notice how the  is only tested when the   statement fails to be true. There can be more than one  expression, allowing multiple tests to be done in a single   statement.

Examples
And the output

False False

High_low.py

Sample run:

Guess a number: 100 Too high Guess a number: 50 Too low Guess a number: 75 Too low Guess a number: 87 Too high Guess a number: 81 Too high Guess a number: 78 Just right

even.py

Sample runs:

Tell me a number: 3 3 is odd.

Tell me a number: 2 2 is even.

Tell me a number: 3.14159 3.14159 is very strange.

average1.py

Sample runs:

Enter 0 to exit the loop Enter a number: 3 Enter a number: 5 Enter a number: 0 The average was: 4.0

Enter 0 to exit the loop Enter a number: 1 Enter a number: 4 Enter a number: 3 Enter a number: 0 The average was: 2.66666666667

average2.py

Sample runs:

This program will take several numbers then average them How many numbers would you like to average: 2 Number 1 Enter a number: 3 Number 2 Enter a number: 5 The average was: 4.0

This program will take several numbers then average them How many numbers would you like to average: 3 Number 1 Enter a number: 1 Number 2 Enter a number: 4 Number 3 Enter a number: 3 The average was: 2.66666666667

Exercises

 * 1) Modify the higher or lower program from this section to keep track of how many times the user has entered the wrong number.  If it is more than 3 times, print "That must have been complicated."  Note that the program does not have to quit asking for the number before it is guessed, it just has to print this after the number is guessed.
 * 2) Write a program that asks for two numbers.  If the sum of the numbers is greater than 100, print "That is a big number."
 * 3) Write a program that asks the user their name, if they enter your name say "That is a nice name", if they enter "John Cleese" or "Michael Palin", tell them how you feel about them ;), otherwise tell them "You have a nice name."


text:
Non-Programmer's Tutorial for Python 2.6/Debugging

What is debugging?

 * "As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought.  Debugging had to be discovered.  I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs." — Maurice Wilkes discovers debugging, 1949

By now if you have been messing around with the programs you have probably found that sometimes the program does something you didn't want it to do. This is fairly common. Debugging is the process of figuring out what the computer is doing and then getting it to do what you want it to do. This can be tricky. I once spent nearly a week tracking down and fixing a bug that was caused by someone putting an  where a   should have been.

This chapter will be more abstract than previous chapters.

What should the program do?
The first thing to do (this sounds obvious) is to figure out what the program should be doing if it is running correctly. Come up with some test cases and see what happens. For example, let's say I have a program to compute the perimeter of a rectangle (the sum of the length of all the edges). I have the following test cases:

I now run my program on all of the test cases and see if the program does what I expect it to do. If it doesn't then I need to find out what the computer is doing.

More commonly some of the test cases will work and some will not. If that is the case you should try and figure out what the working ones have in common. For example here is the output for a perimeter program (you get to see the code in a minute):

Height: 3 Width: 4 perimeter = 15

Height: 2 Width: 3 perimeter = 11

Height: 4 Width: 4 perimeter = 16

Height: 2 Width: 2 perimeter = 8

Height: 5 Width: 1 perimeter = 8

Notice that it didn't work for the first two inputs, it worked for the next two and it didn't work on the last one. Try and figure out what is in common with the working ones. Once you have some idea what the problem is finding the cause is easier. With your own programs you should try more test cases if you need them.

What does the program do?
The next thing to do is to look at the source code. One of the most important things to do while programming is reading source code. The primary way to do this is code walkthroughs.

A code walkthrough starts at the first line, and works its way down until the program is done. loops and  statements mean that some lines may never be run and some lines are run many times. At each line you figure out what Python has done.

Lets start with the simple perimeter program. Don't type it in, you are going to read it, not run it. The source code is:

 * Question: What is the first line Python runs?
 * Answer: The first line is always run first. In this case it is:

 * What does that line do?
 * Prints, waits for the user to type a number in, and puts that in the variable height.

 * What is the next line that runs?
 * In general, it is the next line down which is:

 * What does that line do?
 * Prints, waits for the user to type a number in, and puts what the user types in the variable width.

 * What is the next line that runs?
 * When the next line is not indented more or less than the current line, it is the line right afterwards, so it is:  (It may also run a function in the current line, but that's a future chapter.)                                                                        What does that line do?
 * First it prints, then it prints.

 * Does  calculate the perimeter properly?
 * Let's see, perimeter of a rectangle is the bottom (width) plus the left side (height) plus the top (width) plus the right side (huh?). The last item should be the right side's length, or the height.

 * Do you understand why some of the times the perimeter was calculated "correctly"?                                                                            : It was calculated correctly when the width and the height were equal.

The next program we will do a code walkthrough for is a program that is supposed to print out 5 dots on the screen. However, this is what the program is outputting:

. . ..

And here is the program:

This program will be more complex to walkthrough since it now has indented portions (or control structures). Let us begin.
 * What is the first line to be run?
 * The first line of the file:

 * What does it do?
 * Puts the number 5 in the variable number.

 * What is the next line?
 * The next line is:

 * What does it do?
 * Well,  statements in general look at their expression, and if it is true they do the next indented block of code, otherwise they skip the next indented block of code.

 * So what does it do right now?
 * If  is true then the next two lines will be run.

 * So is ?
 * The last value put into  was   and   so yes.

 * So what is the next line?
 * Since the  was true the next line is:

 * What does that line do?
 * Prints one dot and since the statement ends with a ',' the next print statement will not be on a different screen line.

 * What is the next line?
 * since that is following line and there are no indent changes.

 * What does it do?
 * It calculates, which is the current value of   (or 5) subtracts 1 from it, and makes that the new value of number.  So basically it changes  's value from 5 to 4.

 * What is the next line?
 * Well, the indent level decreases so we have to look at what type of control structure it is. It is a   loop, so we have to go back to the   clause which is

 * What does it do?
 * It looks at the value of number, which is 4, and compares it to 1 and since  the while loop continues.

 * What is the next line?
 * Since the while loop was true, the next line is:

 * What does it do?
 * It prints a second dot on the line.

 * What is the next line?
 * No indent change so it is:

 * And what does it do?
 * It takes the current value of number (4), subtracts 1 from it, which gives it 3 and then finally makes 3 the new value of number.

 * What is the next line?
 * Since there is an indent change caused by the end of the while loop, the next line is:

 * What does it do?
 * It compares the current value of number (3) to 1.  so the while loop continues.

 * What is the next line?
 * Since the while loop condition was true the next line is:

 * And it does what?
 * A third dot is printed on the line.

 * What is the next line?
 * It is:

 * What does it do?
 * It takes the current value of number (3) subtracts from it 1 and makes the 2 the new value of number.

 * What is the next line?
 * Back up to the start of the while loop:

 * What does it do?
 * It compares the current value of number (2) to 1. Since   the while loop continues.

 * What is the next line?
 * Since the while loop is continuing:

 * What does it do?
 * It discovers the meaning of life, the universe and everything. I'm joking. (I had to make sure you were awake.)  The line prints a fourth dot on the screen.

 * What is the next line?
 * It's:

 * What does it do?
 * Takes the current value of number (2) subtracts 1 and makes 1 the new value of number.

 * What is the next line?
 * Back up to the while loop:

 * What does the line do?
 * It compares the current value of number (1) to 1. Since  is false (one is not greater than one), the while loop exits.

 * What is the next line?
 * Since the while loop condition was false the next line is the line after the while loop exits, or:

 * What does that line do?
 * Makes the screen go to the next line.

 * Why doesn't the program print 5 dots?
 * The loop exits 1 dot too soon.

 * How can we fix that?
 * Make the loop exit 1 dot later.

 * And how do we do that?
 * There are several ways. One way would be to change the while loop to:    Another way would be to change the conditional to:    There are a couple others.

How do I fix the program?
You need to figure out what the program is doing. You need to figure out what the program should do. Figure out what the difference between the two is. Debugging is a skill that has to be practiced to be learned. If you can't figure it out after an hour, take a break, talk to someone about the problem or contemplate the lint in your navel. Come back in a while and you will probably have new ideas about the problem. Good luck.


text: Template:Delete

title: Template:Delete


text:
Spanish/Haber

../Verbs/

=Haber=

"Haber" is an irregular verb that means  "to have" in the sense of having done something, or "there is" or "there are". It is used mostly as an auxiliary verb to form the perfect compound tenses (has/had done, etc.)

 * ../Infinitive/: haber
 * ../Present Participle/:  habiendo
 * ../Past Participle/: n/a

../Present/
(aka Present Perfect)

(hecho is the :Past participle: of hacer, meaning "to make" or "to do". Here, it means "done".)
 * Yo he hecho I have done
 * tú has hecho You (informal) have done
 * él/ella/usted ha hecho He/she has, you (respectful) have done
 * nosotros hemos hecho We have done
 * (vosotros habéis hecho) You (plural, informal) have done
 * ellos/ustedes han hecho They / you (plural, formal) have done
 * hay There is / there are (special form)

(Don't know what Yo, tú, él, and so on mean ? They are pronouns.)

../Imperfect/
(aka Pluperfect)

 * Yo había hecho I had done
 * tú habías hecho
 * él/ella/usted había hecho
 * nosotros habíamos hecho
 * (vosotros habíais hecho)
 * ellos/ustedes habían hecho
 * había There was / There were (Special form)

../Preterite/
Haber is used in the preterite exceedingly rarely. Mostly it is used as a literary tense.
 * Yo hube hecho I had done
 * tú hubiste hecho
 * él/ella/usted hubo hecho
 * nosotros hubimos hecho
 * (vosotros hubisteis hecho)
 * ellos/ustedes hubieron hecho
 * hubo There was / There were

../Future/ (Perfect)
(aka Future Perfect)

 * Yo habré hecho I will have done
 * tú habrás hecho
 * él/ella/usted habrá hecho
 * nosotros habremos  hecho
 * (vosotros habréis  hecho )
 * ellos/ustedes habrán hecho
 * habrá There will be

— or —

 * Yo voy a haber hecho I will have done / I'm going to have done
 * tú vas a haber hecho
 * él/ella/usted va a haber hecho
 * nosotros vamos a haber hecho
 * (vosotros vais a haber hecho)
 * ellos/ustedes van a haber hecho

../Subjunctive/

 * Yo haya hecho I may have done or (if) I have done etc.
 * tú hayas hecho
 * él/ella/usted haya hecho
 * nosotros háyamos hecho
 * (vosotros hayáis hecho)
 * ellos/ustedes hayan hecho
 * haya There may be

../Imperfect Subjunctive/

 * Yo hubiera hecho I might have done or (if) I had done
 * tú hubieras hecho
 * él/ella/usted hubiera hecho
 * nosotros hubiéramos hecho
 * (vosotros hubierais hecho)
 * ellos/ustedes hubieran hecho
 * hubiera There might have been

— or —

 * Yo hubiese hecho I might have done or (if) I had done
 * tú hubieses hecho
 * él/ella/usted hubiese hecho
 * nosotros hubiésemos hecho
 * (vosotros hubiesein hecho)
 * ellos/ustedes hubiesen hecho
 * hubiese There might have been

../Conditional/

 * Yo habría hecho I would have done
 * tú habrías hecho
 * él/ella/usted habría hecho
 * nosotros habríamos hecho
 * (vosotros habríais hecho)
 * ellos/ustedes habrían hecho
 * habría There would be

title: Spanish/Haber


text:
Classical Nahuatl

Classical Nahuatl Wikibook
Welcome to the Classical Nahuatl Wikibook. Here you can learn the language that was spoken by the Aztecs in the valley of Mexico at the time of the Spanish Conquest and during the subsequent centuries, which has survived through a multitude of written sources written by Nahuas and Spaniards.

Nochi tlacameh huan cihuameh quipiah manoh cuali tlacaticeh, nochi zan ce totlatechpohuiltiliz huan titlatepanitalohqueh, yeca monequi cuali ma timohuicacah, ma timoicnelicah, ma timotlazohtlacah huan ma timotlepanitacah.

Translation: All human beings are born free and equal in dignity and rights. They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood. (Article 1 of the Universal Declaration of Human Rights)

Courses

 * About Nahuatl
 * /Pronunciation/
 * /Grammar/
 * /Common Words/
 * /Verb List/
 * /Pronouns/
 * /Noun List/
 * /Comparison Words/
 * /Question Words/
 * /Conjunctions/
 * /verb: to want/
 * /Example Sentences/
 * /Incorporation of Foreign Words/

Reference

 * Appendix: Numbers
 * /Common phrases/

title: Classical Nahuatl


text:
Quantum Mechanics/Meaning of Quantum Wave Function

In the classical picture, we usually work with the position and momentum of a particle or particles. From these, we can generate all the physical information about the system.

However, it is easy to see how such an approach will run into serious problems for quantum mechanics. If we consider, for the moment, the Uncertainty Principle to be our definition of Quantum Mechanics then, there is the position of a particle having no simple meaning, as there is an inherent uncertainty in it. Talking about a particular position and momentum is wrong, in quantum mechanics.

To get round this problem, instead of having a particular value of position (or momentum) of a particle, we instead assign a probability to each point in space, of finding the particle there. We could similarly define the probability of it having a particular momentum but, while equally valid, that approach is not initially useful.

Thus, in quantum mechanics, we have a wavefunction, which, as we will see, contains all the information about the system. In general, this wavefunction will be complex. This wavefunction's modulus squared is the probability distribution of the system.

Position (or momentum for that matter) now, is not a variable. Rather, it is an operator. Before we see how it works, let us deviate a little, in order to understand operators better.

Take a two state system for example. By two states, we mean that a particular property (say the color) can have only two values (say Red and Blue). Now, a wavefunction of the system will be a mixture of these states. Let us say R is the wavefunction when the particle is "definitely" Red, and B when it is definitely Blue. So, the general wavefunction, W of the system is a linear combination of the two.

 * $$W = xR + yB $$

where $$|x|^2$$ is the probability that the particle is Red. Since this is a two state system, $$|y|^2 = 1 - |x|^2$$. Be aware that, in general, $$x$$ and $$y$$ may be complex numbers, which is why we must use $$|x|^2$$ rather than $$x^2$$ in order to get a real probability.

Now, the big news. The fundamental assumption of quantum mechanics is that any measurement will send the system into one of that operator's eigenstates. Eigenstates are just the states of a system unchanged by an operator.

In this example, when we measure the color of the system, we multiply it by a color operator, which turns a wavefunction into a color, Red or Blue.

So, Quantum Mechanics says that if you make a measurement of the colour, you will never find the system to be a mixture of Red and Blue! It is only that you will sometimes find it Red, sometimes Blue, with the corresponding probabilities.

If you were to measure some other property of the system, you might find it in a state which you could deduce had mixed color, but you wouldn't be able to observe this mixture. The uncertainty principle stems from this phenomenon.

Measurement is nothing but acting the corresponding operator on our wavefunction. Remember, once we have acted an operator on our wavefunction, the system has already "collapsed" into one of its eigen-states (allowed states). Any subsequent measurements will yield the same result, because the system isn't anymore a mixture of all those eigen-states.

To see the probability effect as stated above, you'll have to prepare the system from scratch. In other words, before making a measurement, prepare infinite mental copies of the system (an ensemble) and then perform the same measurement on each of them.

Coming back to position; this is a special operator, in that its spectrum (the range of eigen-values) is continuous. Our example had a discrete (2 level) system. The details of working out stuff become more complicated for such an operator, but the basic premise remains exactly the same. What happens now? We know that Quantum Mechanics should reduce to Classical Mechanics at a large enough scale. For a single particle, this wavefunction is peaked around the "Classical Position" and the standard deviation is ~ h. So, on normal scales, we won't see this "fuzziness" of the particle.

To see how a result matches with Classical Mechanics, we can use the concept of an "Expectation Value". An expectation value of an operator is just the average value of its eigenvalues, weighted with the corresponding probabilities. It can be shown that the expectation values of position and momentum are related like the classical position and momentum.


text:
Non-Programmer's Tutorial for Python 2.6/Defining Functions

Creating Functions
To start off this chapter I am going to give you an example of what you could do but shouldn't (so don't type it in):

with the output being:

The absolute values of 23 and 23 are equal

The program seems a little repetitive. Programmers hate to repeat things -- that's what computers are for, after all! (Note also that finding the absolute value changed the value of the variable, which is why it is printing out 23, and not -23 in the output.) Fortunately Python allows you to create functions to remove duplication. Here is the rewritten example:

with the output being:

The absolute values of 23 and -23 are equal

The key feature of this program is the  statement. The  keyword (short for "define") starts a function definition. " " is followed by the name of the function " ". Next, comes the single function parameter named, " ". A parameter holds a value passed into the function from the program that "calls" the function. Parameters of a function in the  statement, must be enclosed within a parenthesis. The value that is passed to a function parameter is called an argument. So for now, a parameter and argument points to the same thing. The block of indented statements after the " " are then executed whenever the function is used. The statements within the function continue to be run until either the indented statements end, or a " " statement is encountered. The  statement returns a value back to the place where the function was called in the calling program.

Notice how the values of  and   are not changed. Functions can be used to repeat tasks that don't return values. Here are some examples:

with output being:

Hello Hello Welcome Fred width = 4 height = 5 area = 20

That example shows some more stuff that you can do with functions. Notice that you can use one or more parameters, or none at all. Notice also that a function doesn't necessarily need to "return" a value, so a  statement is optional.

Variables in functions
When eliminating repeated code, you often notice that variables are repeated in the code. In Python, these are dealt with in a special way. So far, all variables we have seen are global variables. Functions work with a special type of variables called local variables. These variables only exist within the function and only while the function is running. When a local variable has the same name as another variable (such as a global variable), the local variable hides the other. Sound confusing? Well, these next examples (which are a bit contrived) should help clear things up.

When run, we will receive an output of:

in print_func a = 17 a = 4 which is global variable assigned prior to the function print_func

Variable assignments inside a function do not override global variables, they exist only inside the function. Even though  was assigned a new value inside the function, this newly assigned value exists only within the   function. After the function finishes running and the value of an  variable is printed again, we see the value assigned to the global   variable being printed.

Complex example
The output is: in a_func a_var = 15 in a_func b_var = 115 in a_func d_var = 30 in a_func c_var = 25 a_var = 10 b_var = 15 c_var = 125 d_var = Traceback (most recent call last): File "C:\Python24\def2", line 19, in -toplevel- print "d_var = ", d_var NameError: name 'd_var' is not defined In this example the variables,  , and   are all local variables when they are inside the function. After the statement  is run, they all cease to exist. The variable  is "automatically" a local variable since it is a parameter named by the function definition. The variables  and   are local variables since they appear on the left of an equals sign within the function in the statements:   and.

Inside of the function  has no value assigned to it. When the function is called with, 15 is assigned to   since at that point in time   is 15, making the call to the function. This ends up setting the value of  to 15 when it is inside of   function.

As you can see, once the function finishes running, the local variables  and   that had hidden the global variables of the same name are gone. Then the statement  prints the value  rather than the value   since the local variable that hid the global variable is gone.

Another thing to notice is the  that happens at the end. This appears since the variable  no longer exists since   finished. All the local variables are deleted when the function exits. If you want to get something back from a function, then you will have to use  statement within the function.

One last thing to notice is that the value of  remains unchanged inside   since it is not a parameter and it never appears on the left of an equals sign inside of the function. When a global variable is accessed inside a function, the function uses only value of the global variable but it cannot change the value assigned to the global variable outside the function.

Functions allow local variables that exist only inside the function and can hide other variables that are outside the function.

Examples
temperature2.py

Sample Run:

Options: 'p' print options 'c' convert from celsius 'f' convert from fahrenheit 'q' quit the program option: c Celsius temperature: 30 Fahrenheit: 86.0 option: f Fahrenheit temperature: 60 Celsius: 15.5555555556 option: q

area2.py

Sample Run:

Your Name: Josh Hello! Welcome, Josh To find the area of a rectangle, enter the width and height below. Width: -4 Must be a positive number Width: 4 Height: 3 Width = 4 Height = 3 so Area = 12

Exercises
Rewrite the area2.py program from the Examples above to have a separate function for the area of a square, the area of a rectangle, and the area of a circle. This program should include a menu interface.


text:
Non-Programmer's Tutorial for Python 2.6/Lists

Variables with more than one value
You have already seen ordinary variables that store a single value. However other variable types can hold more than one value. The simplest type is called a list. Here is an example of a list being used:

and an output example:

What month (1-12)? 3 The month is March

In this example the  is a list. is defined with the lines  and   (note that a   could also be used to split a long line, but that is not necessary in this case because Python is intelligent enough to recognize that everything within brackets belongs together). The  and   start and end the list with commas  separating the list items. The list is used in. A list consists of items that are numbered starting at 0. In other words if you wanted January you would use. Give a list a number and it will return the value that is stored at that location.

The statement  will only be true if   is between one and twelve inclusive (in other words it is what you would expect if you have seen that in algebra).

Lists can be thought of as a series of boxes. Each box has a different value. For example, the boxes created by   would look like this:

Each box is referenced by its number so the statement  would get ,   would get   and so on up to   getting.

More features of lists
The next example is just to show a lot of other stuff lists can do (for once I don't expect you to type it in, but you should probably play around with lists until you are comfortable with them.). Here goes:

The output is:

demolist = ['life', 42, 'the universe', 6, 'and', 9] after 'everything' was appended demolist is now: ['life', 42, 'the universe', 6, 'and', 9, 'everything'] len(demolist) = 7 demolist.index(42) = 1 demolist[1] = 42 demolist[ 0 ] = life demolist[ 1 ] = 42 demolist[ 2 ] = the universe demolist[ 3 ] = 6 demolist[ 4 ] = and demolist[ 5 ] = 9 demolist[ 6 ] = everything After 'the universe' was removed demolist is now: ['life', 42, 6, 'and', 9, 'everything'] 'life' was found in demolist 'amoeba' was not found in demolist The sorted demolist is [6, 9, 42, 'and', 'everything', 'life']

This example uses a whole bunch of new functions. Notice that you can just  a whole list. Next the  function is used to add a new item to the end of the list. returns how many items are in a list. The valid indexes (as in numbers that can be used inside of the ) of a list range from 0 to. The function tells where the first location of an item is located in a list. Notice how  returns 1, and when  is run it returns 42. The line  is a just a reminder to the programmer (also called a comment). Python will ignore any lines that start with a. Next the lines:

create a variable, which starts at 0 and is incremented until it reaches the last index of the list. Meanwhile the  statement prints out each element of the list. The  command can be used to remove a given element in a list. The next few lines use the  operator to test if an element is in or is not in a list. The  function sorts the list. This is useful if you need a list in order from smallest number to largest or alphabetical. Note that this rearranges the list. In summary, for a list, the following operations occur:

This next example uses these features in a more useful way:

And here is part of the output:

1. Print the list 2. Add a name to the list 3. Remove a name from the list 4. Change an item in the list 9. Quit Pick an item from the menu: 2 Type in a name to add: Jack Pick an item from the menu: 2 Type in a name to add: Jill Pick an item from the menu: 1 0 . Jack 1 . Jill Pick an item from the menu: 3 What name would you like to remove: Jack Pick an item from the menu: 4 What name would you like to change: Jill What is the new name: Jill Peters Pick an item from the menu: 1 0 . Jill Peters Pick an item from the menu: 9 Goodbye

That was a long program. Let's take a look at the source code. The line  makes the variable   a list with no items (or elements). The next important line is. This line starts a loop that allows the menu system for this program. The next few lines display a menu and decide which part of the program to run.

The section goes through the list and prints each name. tells how many items are in the list. If  returns , then the list is empty.

Then, a few lines later, the statement  appears. It uses the  function to add an item to the end of the list. Jump down another two lines, and notice this section of code: Here the  function is used to find the index value that will be used later to remove the item. is used to remove a element of the list.

The next section uses  to find the   and then puts   where the   was.

Congratulations, with lists under your belt, you now know enough of the language that you could do any computations that a computer can do (this is technically known as Turing-Completeness). Of course, there are still many features that are used to make your life easier.

Examples
test.py

The values  and   point to 1 and 0, respectively. They are often used in sanity checks, loop conditions etc. You will learn more about this a little bit later (chapter ../Boolean Expressions/).

Sample Output:

What color is the daytime sky on a clear day?green Incorrect, correct was: blue What is the answer to life, the universe and everything?42 Correct What is a three letter word for mouse trap?cat Correct You got 66 % right out of 3

Exercises
Expand the test.py program so it has a menu giving the option of taking the test, viewing the list of questions and answers, and an option to quit. Also, add a new question to ask, "What noise does a truly advanced machine make?" with the answer of "ping".


text:
Non-Programmer's Tutorial for Python 2.6/For Loops

And here is the new typing exercise for this chapter:

and the ever-present output:

1 2 3 4 5 6 7 8 9 10

The output looks awfully familiar but the program code looks different. The first line uses the  function. The  function uses two arguments like this. is the first number that is produced. is one larger than the last number. Note that this program could have been done in a shorter way:

Here are some examples to show what happens with the  command:

>>> range(1, 10) [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> range(-32, -20) [-32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21] >>> range(5,21) [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] >>> range(5) [0, 1, 2, 3, 4] >>> range(21, 5) []

The next line  uses the   control structure. A  control structure looks like. is gone through starting with the first element of the list and going to the last. As  goes through each element in a list it puts each into. That allows  to be used in each successive time the   loop is run through. Here is another example (you don't have to type this) to demonstrate:

The output is:

The Current item is: life The Current item is: 42 The Current item is: the universe The Current item is: 6 The Current item is: and The Current item is: 9 The Current item is: everything

Notice how the  loop goes through and sets item to each element in the list. Notice how if you don't want  to go to the next line add a comma at the end of the statement (i.e. if you want to print something else on that line). So, what is  good for? The first use is to go through all the elements of a list and do something with each of them. Here's a quick way to add up all the elements:

with the output simply being:

The sum is: 20

Or you could write a program to find out if there are any duplicates in a list like this program does:

and for good measure:

Duplicate of 7 Found

Okay, so how does it work? Here is a special debugging version to help you understand (you don't need to type this in):

with the output being:

l = [4, 5, 7, 8, 9, 1, 0, 7, 10]       l: [4, 5, 7, 8, 9, 1, 0, 7, 10] l.sort               l: [0, 1, 4, 5, 7, 7, 8, 9, 10] prev = l[0]            prev: 0 del l[0]               l: [1, 4, 5, 7, 7, 8, 9, 10] if prev == item:       prev: 0         item: 1 prev = item            prev: 1         item: 1 if prev == item:       prev: 1         item: 4 prev = item            prev: 4         item: 4 if prev == item:       prev: 4         item: 5 prev = item            prev: 5         item: 5 if prev == item:       prev: 5         item: 7 prev = item            prev: 7         item: 7 Duplicate of 7 found if prev == item:       prev: 7         item: 7 prev = item            prev: 7         item: 7 if prev == item:       prev: 7         item: 8 prev = item            prev: 8         item: 8 if prev == item:       prev: 8         item: 9 prev = item            prev: 9         item: 9 if prev == item:       prev: 9         item: 10 prev = item            prev: 10        item: 10

The reason I put so many  statements in the code was so that you can see what is happening in each line. (By the way, if you can't figure out why a program is not working, try putting in lots of print statements so you can see what is happening.) First the program starts with a boring old list. Next the program sorts the list. This is so that any duplicates get put next to each other. The program then initializes a (ious) variable. Next the first element of the list is deleted so that the first item is not incorrectly thought to be a duplicate. Next a  loop is gone into. Each item of the list is checked to see if it is the same as the previous. If it is a duplicate was found. The value of  is then changed so that the next time the   loop is run through   is the previous item to the current. Sure enough, the 7 is found to be a duplicate. (Notice how  is used to print a tab.)

The other way to use  loops is to do something a certain number of times. Here is some code to print out the first 9 numbers of the Fibonacci series:

with the surprising output:

1 1 2 3 5 8 13 21 34

Everything that can be done with  loops can also be done with   loops but   loops give an easy way to go through all the elements in a list or to do something a certain number of times.