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
# Let's get CodeFirst in Hacktoberfest... and practice what you have learned this week!
2
+
3
+
1. Go to [https://hacktoberfest.digitalocean.com/](https://hacktoberfest.digitalocean.com/):jack_o_lantern:
4
+
and Sign up using your GitHub account
5
+
2. Make sure that your local repository is up to date (Pull your repo! see the GIF below)
6
+

7
+
3. Also make sure that you are in Master (on GitKraken next to the repository name you should
8
+
see 'master')
9
+
4. Complete the following tasks
10
+
11
+
## Task 1
12
+
1. Open the `team.md` file contained in the Hacktoberfest folder
13
+
. Use atom or sublime to open and modify the file.
14
+
2. Copy the lines in the document and paste them below the dashes (---) replace this with your own personal information and save the document
15
+
3. Stage your files, write a commit message and push to your GitHub account
16
+

17
+
4. Create a pull request from your repository to the main `trallard/Shef_CodeFirst_Python` one
18
+
(remember what we checked in class choose on the right side your repo an on the left one trallard/....)
19
+
20
+
21
+
## Task 2
22
+
Fun with functions!
23
+
1. Create a new script in the Hacktoberfest folder and name it with your own username (e.g for me it would be `trallard.py`)
24
+
2. Remember what we learned about use inputs, variables and printing? In your new script create a code for a very basic Starbucks bot 😜 (check exercise 12 from the book for inspiration). Make sure the bot does the following things:
25
+
1. Ask for the user name
26
+
2. Ask for the order
27
+
3. Ask if you want whole milk or almond milk
28
+
4. Print a statement confirming the order and giving a price for this!
29
+
3. Make sure it runs, save it, commit your changes in Gitkraken and push to your GitHub account.
30
+
4. Create a pull request for this task too!
31
+
32
+
33
+
## Task 3!!! You are almost done! :fire:
34
+
1. Complete Exercise 21 in the Learn the Python the hard way. Save your script as `<username>21.py` (e.g. trallard21.py) in the Hacktoberfest folder.
35
+
2. Once completed commit your changes, and push to your repository!
36
+
3. Make your final pull request to the repository.
37
+
38
+
Remember you have up to 11:59pm October 31st to complete this. If you need any help let us know on Facebook, slack or via email!
Copy file name to clipboardExpand all lines: session-2.md
+12-9Lines changed: 12 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@
22
22
23
23
#### Getting input from a user
24
24
25
-
From last week's session we now know how to create variables and how to print them, but what if we don't know what the value of our variable should be, because we need to get it from a user? Using the method `raw_input()` we can prompt a user for information.
25
+
From last week's session we now know how to create variables and how to print them, but what if we don't know what the value of our variable should be, because we need to get it from a user? Using the method `input()` we can prompt a user for information.
26
26
27
27
28
28
---
@@ -33,7 +33,7 @@ From last week's session we now know how to create variables and how to print th
33
33
34
34
```python
35
35
print("What's your name?")
36
-
name =raw_input()
36
+
name =input()
37
37
print("Hello {}!".format(name))
38
38
```
39
39
@@ -60,16 +60,19 @@ def hello_world():
60
60
61
61
Any time you write a function in Python, it'll have the following things:
62
62
63
-
- def at the very beginning, so that Python knows the indented code below is part of a function (you're "defining" your function below this line).
64
-
- A unique name, with no spaces in it. It's important that you don't have two functions with the exact same name in your code. You also don't want to name your function "function", "sum" or "python" (or later on in this course "email", "mailgun", or "tweepy"). If you name your function after a Python library or package or built-in function, Python will get really confused and your code won't run.
63
+
-**def** at the very beginning, so that Python knows the indented code below is part of a function (you're "defining" your function below this line).
64
+
-**A unique name**, with no spaces in it. It's important that you don't have two functions with the exact same name in your code. You also don't want to name your function "function", "sum" or "python" (or later on in this course "email", "mailgun", or "tweepy"). If you name your function after a Python library or package or built-in function, Python will get really confused and your code won't run.
65
65
66
66
- You'll also need to put brackets and a colon right after the name.
67
67
68
68
Notice how, after the first line of code in a function, the other lines are indented. In Python, this is very important – it's how the code interpreter in your computer knows what's part of your function and what isn't.
69
69
70
70
#### Calling a function
71
71
72
-
A function by itself doesn't actually do anything. You have to "call" it by its name, to run the code inside it. Calling a function is really easy! All you have to do is type the name of your function with () after it, like this: hello_world()
72
+
A function by itself doesn't actually do anything. You have to "call" it by its name, to run the code inside it. Calling a function is really easy! All you have to do is type the name of your function with () after it, like this:
73
+
```python
74
+
hello_world()
75
+
```
73
76
74
77
Notice that the function call is NOT indented, because it's not part of the function definition!
75
78
@@ -144,7 +147,7 @@ You must use variable names for your arguments when you're defining your functio
144
147
145
148
You can use functions to do stuff like crunch numbers or manipulate data, and then "return" information from your function so that you can use it somewhere else in your program.
146
149
147
-
Functions can return a number, a string, a list, or even another function (we'll learn about one called render_template() later on in this course). Today, we're going to learn how to return a simple number value from your function.
150
+
Functions can return a number, a string, a list, or even another function (we'll learn about one called `render_template()` later on in this course). Today, we're going to learn how to return a simple number value from your function.
148
151
149
152
Let's have a look at the code below:
150
153
```python
@@ -169,7 +172,7 @@ If you're returning something, the return statement should be the last line you
169
172
---
170
173
#### Task
171
174
172
-
1. What do you think returned_value will be if you don't have a return line in your function? Copy the code from the example above into your **my_arguments.py** file and run the file. Then remove only the line return answer and see what happens.
175
+
1. What do you think `returned_value `will be if you don't have a return line in your function? Copy the code from the example above into your **my_arguments.py** file and run the file. Then remove only the line return answer and see what happens.
173
176
174
177
----
175
178
@@ -277,7 +280,7 @@ Copy and paste the code below into a new file called **numbers.py** and run the
277
280
278
281
```python
279
282
280
-
number =raw_input("Enter a number between 1 and 10: ")
283
+
number =input("Enter a number between 1 and 10: ")
281
284
number =int(number) #Converts the input string to an integer
282
285
283
286
if number >10:
@@ -294,7 +297,7 @@ if number <=0:
294
297
295
298
If none of your conditions are met, Python will simply carry on through the rest of your code. In the example above, we didn't write any code for the situation where the user enters a number between 1 and 10, so you didn't see any sort of helpful message or feedback in your terminal.
296
299
297
-
Notice how we used `int() `to convert the user input into a number. raw_input() treats all input as a string, so we used information in [Python's documentation](https://docs.python.org/2.7/library/stdtypes.html#typesnumeric) to figure out how to convert the user input to a number. You don't need to worry about this right now, but it's an example of something useful you can do with Python.
300
+
Notice how we used `int() `to convert the user input into a number. input() treats all input as a string, so we used information in [Python's documentation](https://docs.python.org/2.7/library/stdtypes.html#typesnumeric) to figure out how to convert the user input to a number. You don't need to worry about this right now, but it's an example of something useful you can do with Python.
0 commit comments