@@ -489,70 +489,42 @@ print("Your favorite color is %s!" % choice)
489489
490490# # Exercises
491491
492- ** TODO :** more exercises.
493-
494- ** There is a lot to learn about functions, and I don' t expect you to
495- learn everything at once.** However, there' s also lots of free Python
496- exercises about defining functions you can do. Do many of them and
497- spend time with them until you' re familiar with defining functions.
498-
499- 1 . The box printing function doesn' t really print a box, it prints a
500- message between two lines.
501-
502- ** **********
503- Hello World!
504- ** **********
505-
506- Modify it to print an actual box:
507-
508- ** **************
509- * Hello World! *
510- ** **************
511-
512- 2 . Python comes with many built- in functions. Some of the simplest ones
513- are abs , all and any . They can be used like this:
514-
515- - abs returns the absolute value of its only argument.
516-
517- ```py
518- >> > abs (1 )
519- 1
520- >> > abs (- 1 )
521- 1
522- >> >
523- ```
524-
525- - any returns True if one or more of the elements of a list is true,
526- and False otherwise.
527-
528- ```py
529- >> > any ([True , False , True ])
530- True
531- >> > any ([False , False , False ])
532- False
533- >> >
534- ```
535-
536- - all returns True if all elements of a list are true, and False
537- otherwise.
538-
539- ```py
540- >> > all ([True , True , True ])
541- True
542- >> > all ([True , False , True ])
543- False
544- >> >
545- ```
546-
547- Define functions `my_abs` , `my_all` and `my_any` that work the same
548- way without using the built- in functions. Then run the program with
549- IDLE , or with `py - i file .py` on Windows or `python3 - i file .py` on
550- other operating systems. Try the above examples with your
551- functions.
552-
553- 2 . Find more exercises about defining functions online.
554-
555- Answers for the first and second exercise are [here](answers.md).
492+ ** There are many things to learn about functions, and I don' t expect
493+ you to learn everything at once.** However, there are also many free
494+ exercises about defining functions you can do.
495+
496+ 1 . What' s wrong with this code?
497+
498+ ```py
499+ def ask_name():
500+ name = input (" Enter your name: " )
501+
502+ ask_name()
503+ print (" Your name is" , name)
504+ ```
505+
506+ 2 . How about this code?
507+
508+ ```py
509+ def get_greeting():
510+ return " Hello World!"
511+
512+ print (get_greeting)
513+ ```
514+
515+ 3 . Why does this print None after greeting the world?
516+
517+ ```py
518+ def greet(target):
519+ print (" Hello" , target)
520+
521+ print (greet(" World" ))
522+ ```
523+
524+ 4 . Find more exercises about defining functions online.
525+
526+ Answers for the first, second and third exercise are
527+ [here](answers.md# defining-functions).
556528
557529** *
558530
0 commit comments