Chapter 1: In which a cow surprises you

Start Here

Chapter 1: In which a cow surprises you 

Chapter 2: The Time traveling cow

Chapter 3: Greedy banker strings

Chapter 4: More on strings and donkeys

Chapter 5: Crooks R Us Bank & Lists

Chapter 6: Orc functions

Chapter 7: Dictionaries, Locks, and Gobbledygook

Chapter 8: Python vs the Zombies

Chapter 9: The Doggy-Nator and List Comprehensions

Chapter 10: In which you Eval the Doggy


Night of the living Cows

You are walking down the alley. It’s late at night, and after a night of partying and clubbing, you are going home to your mansion, your racing car, and your beautiful wife/husband.

Just kidding.

You live alone in a broken cockroach infested home, and you haven’t been partying, you have been crying over your wasted life. You would cry over the shoulder of friends, if you had any. You decide to take a short cut through a slightly shady part of town.

“Who will rob me? I hain’t got two pence to my name,” you think to yourself. You a talk like a hillybilly, because you are a hillybilly(if it helps).

That’s when you hear and see a thunder flash. Sparks fly all around you, and you have to cover your eyes to protect them. When you open them, you see a naked cow kneeling in front of you. The cows says “Hello World!”

Okay, open up your Python console, and type this:

You should see “Hello World” printed on your screen. If you see “Kill them all, and burn down the house” instead, please stop reading immediately, and see your psychiatrist. Again. Thank you.

The cow sees you, and starts walking towards you. Being the coward you are, you want to run away, but are too scared to. The cow walks right up to you.

You are too scared to say anything, and stare stupidly at the cow. So Moo-Inator repeats the question.

To read user values in Python, the function is raw_input(). Additionally, you can enter some text in the brackets. Try this:

The Python console will ask for your name. Whatever you enter will be printed on the next line. But that isn’t good enough. We need to store the variable.

The name is now stored in the variable called name. Why would you do that? (Other than because I told you to?) Because you can use this variable.

Python allows you to join strings using a simple ‘+’ sign. In the example above, we joined “Hello” with the name you entered, and then “How are you?”

Try it:

In which you whimper like a coward

As you see the Moo-Inator walking towards you, you start shivering with fear (being the coward you are). You fall to the ground and start crying. Seriously, you are such a little girl.

Terrified out of your wits, you say, “Please don’t kill me,” five times.

Just to humor me, type this 5 times.

That’s a bit slow, isn’t it, even for you? Surely, I hear you say, there must be a better way. Yes sir/ma’am, there is!

Type this:

We are going to come back to this, so don’t worry if you don’t understand everything. The range() function returns a list of numbers. As you can see, they start from 0, for reasons too geeky to explain here.

Do this now:

A few things: Python is a very, how can I say this politely, anal language. Python is your fat aunt Martha who wags her finger at you and asks you why you haven’t made your bed, and how you will never amount to anything. Python is the skinny girl at your Yoga class lecturing you to eat more green. Python is the grammar nerd, telling you you used the word irony incorrectly. You get the idea. Python is really anal about whitespace. There are a few places you must use whitespaces, and I will tell you where. For those who know some programming, this is any loop, if condition, classes etc. So if you type this:

That is Python moaning you did not use enough whitespace. So you must have a few empty spaces on the second line. Like this:

The Moo-Inator offers you its hand. “Caam weethe mee, eef you waaant tu leeeve,” it says in a heavy Austrian accent. Oh my God, you think. The cow is from Austria. You can trust it then. Austrians cows have never killed anyone, to your knowledge, and you see no reason to doubt all that stuff you have read on the internets.

Leave a Reply

Your email address will not be published. Required fields are marked *