Skip to content

Commit 7c0c078

Browse files
committed
python tutorial
1 parent f9dd120 commit 7c0c078

2 files changed

Lines changed: 90 additions & 3 deletions

File tree

python/lesson1/tutorial.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ If you see it, make sure you're running Python 2, not Python 3, otherwise parts
3434

3535
## Hello, World!
3636

37-
In keeping with tradition, we're going start by printing "Hello, World!" to the console. In Python, the command to achieve this is aptly named `print`. Type the following:
37+
In keeping with tradition, we're going to start by printing "Hello, World!" to the console. In Python, the command to achieve this is aptly named `print`. Type the following:
3838

3939
print "Hello, World!"
4040

@@ -60,7 +60,7 @@ Subtraction, multiplication and division work the same way.
6060
8 * 4
6161
9 / 3
6262

63-
Now try a few more to see what you get.
63+
Now try a few more to see what results you get.
6464

6565
Let's see what happens when you divide 14 by 4. Notice the remainder is chopped off. We can use the *modulus* operator, `%`, to get the remainder instead. Try `14 % 4` and see.
6666

@@ -78,7 +78,7 @@ Did you notice any unexpected results when you started combining operations? If
7878

7979
10 - 2 * 4
8080

81-
Python follows the traditional mathematical rules of precedence, which state that multiplication and division are done before addition and subtraction. (You may remember what *BODMAS* means.) This means in our example above, 2 and 4 are multiplied first, and then the result is subtracted from 10.
81+
Python follows the traditional mathematical rules of precedence, which state that multiplication and division are done before addition and subtraction. (You may remember *BODMAS*.) This means in our example above, 2 and 4 are multiplied first, and then the result is subtracted from 10.
8282

8383
We can change the order of operations by using parentheses. Anything inside parentheses is executed first.
8484

python/lesson2/tutorial.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
layout: page
3+
title: Python tutorial 2
4+
---
5+
6+
In this tutorial we are going to look at variables, user input and decision making.
7+
8+
##Creating a variable
9+
10+
Python allows us to store data in something called variables so that we are able to use this data at a later point. To place an item in a variable we give it a name then set its value.
11+
12+
Now in the REPL type:
13+
14+
year = 2015
15+
16+
In this example you have now stored the value `2015` into the variable `year`. See what happens next when you type `year' into the REPL. Does it show it back to you?
17+
18+
How about saving your age into a variable or your lucky number? Have a play around with storing numbers into variables. Let us know if you think of something more exciting to store in variables than the year.
19+
20+
##Storing numbers in variables
21+
22+
Now that you are familair with the use of variables, we are able to combine variables with the maths operations we learnt in the previous tutorial.
23+
24+
Now in the REPL type the following:
25+
26+
revenue = 1000
27+
costs = 200
28+
profit = revenue - costs
29+
30+
Now type `profit` to see the results of this calculation.
31+
32+
How much money would a sponsor at codebar spend on pizza if they had 60 students turn up?
33+
34+
Along with pizza, students and cost, what oher variables can you think of that could go into this calculation?
35+
36+
##Storing text in variables
37+
38+
As well as numbers varaiables are able to store text, known in Python as string.
39+
40+
Now in the REPl type:
41+
42+
name = 'codebar'
43+
url = "codebar.io"
44+
45+
Now type `name' and `url` to see these strings shown back to you. As you can see Python allows both single and double quotes to denote a string variable. Double quotes are required if there is going to be an apostrophe in the string.
46+
47+
For exmaple:
48+
49+
message = "I'm a string"
50+
51+
Try storing a string within a varable without quotes, see what happens? Numbers do not require quotation marks, whereas they are mandatory for storing strings.
52+
53+
Now store some strings in variables that contain apostrophes and some that do not.
54+
55+
What happens when you store a number in a variable wrapped in quotes?
56+
57+
##Storing user input in variables
58+
59+
Now we are going to look at capturing user input using the python input command.
60+
61+
Let's create a variable in which to store the user input. Now type this into your REPL:
62+
63+
question = input("What is your lucky number?")
64+
65+
Type back your answer after it asks you.
66+
67+
Now remember how strings need either single or double quotes?
68+
69+
Now in the REPL type:
70+
71+
food = input("What is your favouirte food?")
72+
73+
When you give the REPL your repsonse make sure you wrap it in quotes as this is storing your response as a string.
74+
75+
Now try:
76+
77+
name = input("What is your name?")
78+
greeting = "Hello " + name
79+
80+
Then type `message` into your REPL to receive your message.
81+
82+
83+
### Further Reading
84+
85+
86+
ADD NOTE ABOUT NAMING VARIABLE!
87+

0 commit comments

Comments
 (0)