Page 113 - TCS ICT Book 8
P. 113

The City School  2021-2022





             5.10.  Python Functions

             In Python, a function is a group of related statements that perform a specific task.

             Functions help break our program into smaller and modular chunks. As our program
             grows larger and larger, functions make it more organized and manageable.

             Furthermore, it avoids repetition and makes code reusable. Function names cannot
             have spaces in between. Instead of spaces use _ underscore to connect the words.

             In Python, a function is defined using the def keyword and for executing the function
             we can use the function name along with parentheses ().

             The sample code below demonstrates how functions are used in python:                                   Programming Robots & Single-Board Computers


             Sample code:

             # This declares the function called my_function()
             def my_function():

               print(“Hello from a function”)

             # Calling the function
             my_function()

             Output:

             Hello from a function


             5.11.  Getting Started with Python and Raspberry Pi


             One of the classic electronic analogy to “Hello World”

             is to make an LED blink. It is one of the very basic
             tutorials to begin with. To get started, you first of all

             need to build the circuit on the breadboard; a board
             for electronic prototyping.


             Equipment needed

             Following componentes are required for this project:

             •  1 breadboard

             •  1 LED

             •  2 jumper wires
             •  1 resistor: 220Ω/1KΩ










                                                                                                                113
   108   109   110   111   112   113   114   115   116   117   118