@@ -66,7 +66,7 @@ SyntaxError: invalid syntax
66
66
>> >
67
67
```
68
68
69
- Functions like ` print ` need ` () ` after their name to work. But ` if ` is
69
+ ** Functions** like ` print ` need ` () ` after their name to work. But ` if ` is
70
70
a keyword, not a function, so it doesn't need ` () ` . Python has separate
71
71
functions and keywords because it's possible to create custom functions,
72
72
but it's not possible to create custom keywords. That's why keywords are
@@ -286,52 +286,47 @@ else:
286
286
287
287
## Exercises
288
288
289
- 1 . Write a program into a file that asks the user to write a word and
289
+ 1 . This program contains several problems. Copy-paste it to a file,
290
+ then try to run it, fix the errors you got, try to run it again and
291
+ keep going until it works.
292
+
293
+ ``` py
294
+ print (Hello!)
295
+ something == input (' Enter something: )
296
+ print (' You entered:' something)
297
+ ```
298
+
299
+ 2 . Fix this program the same way:
300
+
301
+ ```py
302
+ print (' Hello!' )
303
+ something = input (" Enter something: " )
304
+ if something = ' hello' :
305
+ print (" Hello for you too!" )
306
+ elif something = ' hi'
307
+ print (' Hi there!' )
308
+ else :
309
+ print (" I don't know what," something, " means." )
310
+ ```
311
+
312
+ 3 . Write a program into a file that asks the user to write a word and
290
313
then prints that word 1000 times. For example, if the user enters
291
- ` hi ` the program would reply ` hihihihi... ` .
314
+ `hi` the program would reply `hihihihi` and so on .
292
315
293
- 2 . Add spaces between the words, so the output is like ` hi hi hi ... ` .
316
+ 4 . Add spaces between the words, so the output is like `hi hi hi` and
317
+ so on.
294
318
295
- 3 . Make something that asks the user to enter two words, and prints
319
+ 5 . Make something that asks the user to enter two words, and prints
296
320
1000 of each with spaces in between. For example, if the user
297
321
enters `hello` and `hi` the program would print
298
- ` hello hi hello hi hello hi... ` .
322
+ `hello hi hello hi hello hi` and so on .
299
323
300
- 4 . Make a program that asks for a password and prints ` Welcome! ` ,
324
+ 6 . Make a program that asks for a password and prints `Welcome!` ,
301
325
`Access denied` or `You didn' t enter anything` depending on whether
302
326
the user entered the correct password, a wrong password, or nothing
303
327
at all by pressing Enter without typing anything.
304
328
305
- 5 . Make a program that asks for username and password and checks them.
306
- Make users "foo" and "bar" with passwords "biz" and "baz".
307
-
308
- Example output:
309
-
310
- ```
311
- >>> ================================ RESTART ================================
312
- >>>
313
- Enter your username: foo
314
- Enter your password: biz
315
- Welcome foo!
316
- >>> ================================ RESTART ================================
317
- >>>
318
- Enter your username: bar
319
- Enter your password: baz
320
- Welcome bar!
321
- >>> ================================ RESTART ================================
322
- >>>
323
- Enter your username: spam
324
- Enter your password: eggs
325
- Wrong username.
326
- >>> ================================ RESTART ================================
327
- >>>
328
- Enter your username: foo
329
- Enter your password: lol
330
- Wrong password!
331
- >>>
332
- ```
333
-
334
- The answers are [here](answers.md).
329
+ The answers are [here](answers.md# if-else-and-elif).
335
330
336
331
** *
337
332
0 commit comments