##Step 1
Register on c9.io
##Step 2
Select to create a new workspace
##Step 1
Open up your workspace on c9.io and activate the bash.
Type in
python3
In previous entries we have been mostly manipulating strings and numbers. The numbers have had to be hard set inside the file.
eg
area = 5 * 3
print(area)This is obviously useful for learning, but in real world programming. You must admit input from the users.
##Step 1
In programming, recurrence happens a lot. In fact it can be said that the entire essence of programming is to automate recurring steps.
Suppose for example we needed to have python print out a list of all numbers between 1-10 how would we do it?
Lets first create the folder for the lesson. From the terminal type in
mkdir 5lesson
Functions are programming constructs that helps us package common operations. In addition they make our code that much more readable.
They have a format that looks like this:
def first_function():
pass
output = first_function()We make choices in everyday life. Each choice takes us to a different branch of steps.
For example, you can chose to come by Matatu or by an Uber. Each choice has steps that follow naturally from it.
Computers can also be programmed to make choices. In python, this is done by using the if, elif* and else key words.
if some_true_value:
##Run some series of steps
elif some_other_true_value:So far we have learned a lot about using the python api. While it is possible to build anything you want, most of the time it makes much more sense to resuse something that already exists.
Python comes prepackaged with a lot of libraries that offer common functionality https://docs.python.org/3/library/
Python's extensive library includes everything from mathematical functions to compression functionality.
For this class we shall be looking at the two most commonly used libraries, OS and Math. We shall also take a look at an important library for working with remote resources urllib.
##Step 1
In this challenge we will be exercises our skills in:
The requirement we need delivered is.
As a reader, I want the system to ask me for the post ID that am interestd in and then fetch the post for me.
As we end this semester, we will do so with building a small game.
The point of the game is to guess the number that the machine has. You will get feedback in terms of clues on how you are doing, either good or bad.
The requirements are:
As a gamer I want the script to generate a random number between 1 and 100 which I don't know
As a gamer I want the script to ask me for my own guess of the number, if am wrong, then I should be given a clue as to weather my guess is too high or too low.