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
+24-11Lines changed: 24 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ title: Python tutorial 2
5
5
6
6
In this tutorial we are going to look at variables, user input and decision making.
7
7
8
-
##Creating a variable
8
+
### Creating a variable
9
9
10
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
11
@@ -17,7 +17,7 @@ In this example you have now stored the value `2015` into the variable `year`. S
17
17
18
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
19
20
-
##Storing numbers in variables
20
+
### Storing numbers in variables
21
21
22
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
23
@@ -33,7 +33,7 @@ How much money would a sponsor at codebar spend on pizza if they had 60 students
33
33
34
34
Along with pizza, students and cost, what oher variables can you think of that could go into this calculation?
35
35
36
-
##Storing text in variables
36
+
### Storing text in variables
37
37
38
38
As well as numbers varaiables are able to store text, known in Python as string.
39
39
@@ -54,13 +54,13 @@ Now store some strings in variables that contain apostrophes and some that do no
54
54
55
55
What happens when you store a number in a variable wrapped in quotes?
56
56
57
-
##Storing user input in variables
57
+
### Storing user input in variables
58
58
59
59
Now we are going to look at capturing user input using the python input command.
60
60
61
61
Let's create a variable in which to store the user input. Now type this into your REPL:
62
62
63
-
question = input("What is your lucky number?")
63
+
lucky_number = input("What is your lucky number?")
64
64
65
65
Type back your answer after it asks you.
66
66
@@ -74,14 +74,27 @@ When you give the REPL your repsonse make sure you wrap it in quotes as this is
74
74
75
75
Now try:
76
76
77
-
name = input("What is your name?")
78
-
greeting = "Hello " + name
77
+
my_name = input("What is your name?")
78
+
greeting = "Hello " + my_name
79
79
80
-
Then type `message` into your REPL to receive your message.
81
-
80
+
Then type `greeting` into your REPL to receive your message.
82
81
83
-
### Further Reading
84
82
83
+
### Decision making using variables
84
+
85
+
Now that we know how to use variables and know how to store data, let's play round with decision making and changing input based on your answer.
86
+
87
+
In this final exercise we are going to ask you the number of coffees you have drank todaya and then change the statament back at you depending on your answer.
88
+
89
+
Let's create a variable called:
85
90
86
-
ADD NOTE ABOUT NAMING VARIABLE!
91
+
coffee = input("How many cups of coffee have you consumed today?")
0 commit comments