Skip to content

Commit 19fe701

Browse files
committed
final tweeks
1 parent 88f634b commit 19fe701

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

python/lesson2/tutorial.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Now in the REPL type:
1515

1616
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?
1717

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.
18+
How about saving your age into a variable or your lucky number? Have a play around with storing numbers into variables.
1919

2020
### Storing numbers in variables
2121

@@ -29,13 +29,13 @@ Now in the REPL type the following:
2929

3030
Now type `profit` to see the results of this calculation.
3131

32-
How much money would a sponsor at codebar spend on pizza if they had 60 students turn up?
32+
Now work out how much money a sponsor at codebar would spend on pizza if they had 60 students turn up?
3333

3434
Along with pizza, students and cost, what oher variables can you think of that could go into this calculation?
3535

3636
### Storing text in variables
3737

38-
As well as numbers varaiables are able to store text, known in Python as string.
38+
As well as numbers varaiables are able to store text, known in Python as strings.
3939

4040
Now in the REPl type:
4141

@@ -48,6 +48,10 @@ For exmaple:
4848

4949
message = "I'm a string"
5050

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+
53+
message ='I\'m a string'
54+
5155
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.
5256

5357
Now store some strings in variables that contain apostrophes and some that do not.
@@ -56,43 +60,51 @@ What happens when you store a number in a variable wrapped in quotes?
5660

5761
### Storing user input in variables
5862

59-
Now we are going to look at capturing user input using the python input command.
63+
Now we are going to look at capturing user input using the python input command. Let's create a variable in which to store the user input.
6064

61-
Let's create a variable in which to store the user input. Now type this into your REPL:
65+
Now type this into your REPL:
6266

6367
lucky_number = input("What is your lucky number?")
6468

6569
Type back your answer after it asks you.
6670

67-
Now remember how strings need either single or double quotes?
68-
6971
Now in the REPL type:
7072

71-
food = input("What is your favouirte food?")
73+
food = input("What is your favourite food?")
7274

7375
When you give the REPL your repsonse make sure you wrap it in quotes as this is storing your response as a string.
7476

77+
Now we are going to put your response into another variable.
78+
7579
Now try:
7680

7781
my_name = input("What is your name?")
7882
greeting = "Hello " + my_name
7983

8084
Then type `greeting` into your REPL to receive your message.
8185

82-
8386
### Decision making using variables
8487

85-
Now that we know how to use variables and know how to store data, let's play round with decision making and changing prints based on your answer. 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 certain lines are not indented correctly the code will not run.
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:
89+
90+
if number > 3:
91+
print "Bigger than three"
92+
elif number < 3:
93+
print "Smaller than three"
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.
96+
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.
8698

87-
In this final exercise we are going to ask you the number of coffees you have drank today and then change the statament back at 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 statament returned to you, depending on your answer.
88100

89101
Let's create a variable called:
90102

91103
coffee = input("How many cups of coffee have you consumed today?")
92104

93105
if coffee >= 4:
94106
print "You have a coffee problem"
95-
else:
107+
elif:
96108
print "You do not have a coffee problem"
97109

98110

0 commit comments

Comments
 (0)