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
@@ -104,7 +104,7 @@ Exercises: Variables and Mathematics
104
104
105
105
### Average calculator ###
106
106
107
-
The first two lines of this program put two numbers entered by the user into variables `a` and `b`. (The `input` function is like `raw_input`, but returns a number (e.g. `42`) when you enter one, rather than a string (like `"42"`).) Replace the comment with code that averages the numbers and puts them in a variable called `average`.
107
+
The first two lines of this program put two numbers entered by the user into variables `a` and `b`. (The `input` function is like `input`, but returns a number (e.g. `42`) when you enter one, rather than a string (like `"42"`).) Replace the comment with code that averages the numbers and puts them in a variable called `average`.
108
108
109
109
~~~~~python
110
110
a =input("Enter first number: ")
@@ -147,7 +147,7 @@ False
147
147
`if` statements execute code only if their condition is true. The code to include in the `if` is denoted by a number of indented lines (see the concept section on [code blocks][block]). To indent a line, press the tab key or insert four spaces at the start. You can also include an `else` statement, which is executed if the condition is false. For example:
148
148
149
149
~~~~~python
150
-
name =raw_input("What is your name?")
150
+
name =input("What is your name?")
151
151
if name =="Tim":
152
152
print("Hello Tim.")
153
153
print("You've got an email.")
@@ -206,7 +206,7 @@ In most other programming languages, if you don't indent your code it will run j
206
206
A group of consecutive statements that are all indented by the same distance is called a block. `if` statements, as well as functions and loops, all refer to the block that follows them, which must be indented further than that statement. An example is in order. Let's expand the first `if` example:
207
207
208
208
~~~~~python
209
-
name =raw_input("What is your name?")
209
+
name =input("What is your name?")
210
210
email ="Bank of Nigeria: Tax Refund"
211
211
if name =="Tim":
212
212
print("Hello Tim.")
@@ -387,17 +387,17 @@ Exercises: Lists and Loops
387
387
Write a program which calculates the average of a list of numbers. You can specify the list in the code.
388
388
389
389
**Extension:**
390
-
You can tell when a user has not entered anything at a `raw_input` prompt when it returns the empty string, `""`. Otherwise, it returns a string (like "42.5"), which you can turn into a number with the `float` function. For example:
390
+
You can tell when a user has not entered anything at a `input` prompt when it returns the empty string, `""`. Otherwise, it returns a string (like "42.5"), which you can turn into a number with the `float` function. For example:
391
391
392
392
~~~~~python
393
-
var =raw_input("Enter a number: ")
393
+
var =input("Enter a number: ")
394
394
if var =="":
395
395
print("You didn't enter anything!")
396
396
else:
397
-
print("You entered",float(var))
397
+
print("You entered",float(var))
398
398
~~~~~
399
399
400
-
Now, extend your program to let the user enter the list of values. Stop asking for new list entries when they do not enter anything at the `raw_input` prompt.
400
+
Now, extend your program to let the user enter the list of values. Stop asking for new list entries when they do not enter anything at the `input` prompt.
0 commit comments