Posts

Showing posts with the label Control Structures

Modules

Image
A python module can be defined as a python program file which contains a python code including python functions, class, or variables. In other words, we can say that our python code file saved with the extension (.py) is treated as the module. We may have a runnable code inside the python module. Modules in Python provides us the flexibility to organize the code in a logical way. To use the functionality of one module into another, we must have to import the specific module. Example In this example, we will create a module named as file.py which contains a function func that contains a code to print some message on the console. Let's create the module named as file.py. Here, we need to include this module into our main module to call the method displayMsg() defined in the module named file. LOADING THE MODULE IN OUR PYTHON CODE We need to load the module in our python code to use its functionality. Python provides two types of statements as defined below. The import statement The f...

Control Structures

Image
Control Structures are just a way to specify the flow of control in programs. Any algorithm or program can be more clear and understood if they use self-contained modules called logic or control structures. It basically analyzes and chooses in which direction a program flows based on certain parameters or conditions. There are three basic types of logic, or flow of control, known as: Decision Making Statements Loops Control Statements DECISION-MAKING STATEMENTS Decision-making is the anticipation of conditions occurring while execution of the program and specifying actions taken according to the conditions. As the name implies, decision-making allows us to run a particular block of code for a particular decision. Decision structures evaluate multiple expressions which produce TRUE or FALSE as outcomes. You need to determine which action to take and which statements to execute if the outcome is TRUE or FALSE otherwise. Here, the decisions are made on the validity of the particular condi...