You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: python/lesson2/tutorial.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
layout: page
3
-
title: Python tutorial 2
3
+
title: Playing with variables
4
4
---
5
5
6
6
In this tutorial we are going to look at variables, user input and decision making.
@@ -19,7 +19,7 @@ How about saving your age into a variable or your lucky number? Have a play arou
19
19
20
20
### Storing numbers in variables
21
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.
22
+
Now that you are familiar with the use of variables, we are able to combine variables with the maths operations we learnt in the previous tutorial.
23
23
24
24
Now in the REPL type the following:
25
25
@@ -44,15 +44,15 @@ Now in the REPL type:
44
44
45
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
46
47
-
For exmaple:
47
+
For example:
48
48
49
49
message = "I'm a string"
50
50
51
51
Sometimes you will need to use an apostrophe within a single quote, on occasions like this it is recommended to use string escaping. This would look like:
52
52
53
53
message ='I\'m a string'
54
54
55
-
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.
55
+
Try storing a string within a variable without quotes, see what happens? Numbers do not require quotation marks, whereas they are mandatory for storing strings.
56
56
57
57
Now store some strings in variables that contain apostrophes and some that do not.
58
58
@@ -85,18 +85,18 @@ Then type `greeting` into your REPL to receive your message.
85
85
86
86
### Decision making using variables
87
87
88
-
Now that we know how to use variables and know how to store data, let's play around with decision making and changing prints based on your answer. In Python (and many other languages), one of the most commons ways in which this is done is using an if statement. For example:
88
+
Now that we know how to use variables and know how to store data, let's play around with decision making and changing prints based on your answer. In Python (and many other languages), one of the most common ways in which this is done is using an if statement. For example:
89
89
90
90
if number > 3:
91
91
print "Bigger than three"
92
92
elif number < 3:
93
93
print "Smaller than three"
94
94
95
-
Here we can see that if a number we have passed into this decision making code is bigger than three, we will recieve a messag telling us so, and the same relevant message if the number is smaller than three.
95
+
Here we can see that if a number we have passed into this decision making code is bigger than three, we will receive a message telling us so, and the same relevant message if the number is smaller than three.
96
96
97
97
Also, now that we are getting more in depth with Python, we should say that Python is very particular about tabbing. Tabbing is the indents created when writing code. With Python, if any lines are not indented correctly the code will not run. If you are running into bugs, this is a good place to start.
98
98
99
-
In this final exercise we are going to ask you the number of coffees you have drank today and then change the statament returned to you, depending on your answer.
99
+
In this final exercise we are going to ask you the number of coffees you have drank today and then change the statement returned to you, depending on your answer.
0 commit comments