Skip to content

Commit 85ea71d

Browse files
author
Tania Allard
committed
Minor corrections
1 parent 476b70d commit 85ea71d

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

session-2.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#### Getting input from a user
2424

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.
2626

2727

2828
---
@@ -33,7 +33,7 @@ From last week's session we now know how to create variables and how to print th
3333

3434
```python
3535
print("What's your name?")
36-
name = raw_input()
36+
name = input()
3737
print("Hello {}!".format(name))
3838
```
3939

@@ -60,16 +60,19 @@ def hello_world():
6060

6161
Any time you write a function in Python, it'll have the following things:
6262

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.
6565

6666
- You'll also need to put brackets and a colon right after the name.
6767

6868
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.
6969

7070
#### Calling a function
7171

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+
```
7376

7477
Notice that the function call is NOT indented, because it's not part of the function definition!
7578

@@ -144,7 +147,7 @@ You must use variable names for your arguments when you're defining your functio
144147

145148
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.
146149

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.
148151

149152
Let's have a look at the code below:
150153
```python
@@ -169,7 +172,7 @@ If you're returning something, the return statement should be the last line you
169172
---
170173
#### Task
171174

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.
173176

174177
----
175178

@@ -277,7 +280,7 @@ Copy and paste the code below into a new file called **numbers.py** and run the
277280

278281
```python
279282

280-
number =raw_input("Enter a number between 1 and 10: ")
283+
number =input("Enter a number between 1 and 10: ")
281284
number =int(number) #Converts the input string to an integer
282285

283286
if number > 10:
@@ -294,7 +297,7 @@ if number <=0:
294297

295298
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.
296299

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.
298301

299302
---
300303

0 commit comments

Comments
 (0)