We saw before how programming a computer to do things takes a lot of work: logical gates, switches, and all sorts of madness. Luckily, these things are all already made and integrated into the computer and, more luckily, people have already created relatively nice ways of telling computers what we want them to do! One way that we tell computers what we want is by creating a program. The steps go something like this: we tell the computer what we want via some programming language, another program translates our program into 0's and 1's which the computer understands, and then the computer does what we want (most of the time).
We'll be going back down into the trenches in the next section to work at an extremely basic level, but for now I want to illustrate some of the things you can do (in general) with computers. Because of this, we're going to learn a programming language which is relatively refined and nice called Python.
One of the nice things about Ubuntu is that almost everything is already preloaded. We only need to download one thing, and we'll go through that now:
Downloading IDLE: When you're in Ubuntu, you'll see this little button on the left side called the "terminal" that has a little that has something which looks like a > _ on a little screen. Click this and a big black box with text should appear. Type out:
sudo apt-get install idle
And it'll ask for your password. Provide it (note that it doesn't do that **** thing when you enter your password; it doesn't actually show anything, but just go with it) and it will automatically download idle. Neat. When it's done, you can type in "idle" to the terminal and it will pull up the program. This is the program you'll use to make python programs. We'll do that below!
Read this from "Using the Python Shell" onward; note that we get to IDLE through the terminal by typing "idle" (as above). Read and make the program examples and make sure that they run correctly.
You don't need to read all of this (most of it won't be useful to you), but it's there when you want to know how to do a certain task.
Create a Python program which adds up the positive multiples of 3 which are less than 1000. (So, I want 3 + 6 + 9 + ... ).
Create a Python program which asks the user for their name and then says, "Hello " and then their name.
[Hint, you may use the raw_Input("") command to ask them their name. For example, you may type name = raw_input("What is your name?") to ask their name and save it as the variable name.]
Create a Python program which asks the user for their favorite number, then multiply that number by 2 and raise the result to the power of 3.
[Hint, you may use the input("") command to ask them their favorite number like this: favnumber = input("What is your favorite number?") which will store their favorite number as a variable. The reason we don't use raw_input this time is because raw_input stores their input as a string (which is like a word) which we usually can't use as a number. input will store it as a number which we can use to do some math.]
Create a Python program that asks the user to input any word, and then prints the first and last letter of their word.
[Hint, use raw_input here. You may also find this section useful.]
Create a Python program which asks the user for a number. If that number is greater than 10, have the program print "Big". If that number is not greater than 10, have the program print "Small."
Create a Python program which creates a list that has the numbers from 0 to 100 in it, then removes any even numbers and prints the new list.
[Hint, this one is harder; you may have to do a "for" loop, and then inside of that do an "if" statement. To test if a number if even, you can say, if number%2 == 0: as this will say, "is the number divisible by 2 evenly?"]
In general, you can do quite a bit with Python; this is not even the tip of the iceberg.
|⇐ Back to 1.1||Home||Onwards to 2.2 ⇒|