Program Logic Formulation and Computer Programming PDF

Summary

These notes cover fundamental concepts in programming like Scratch, which is a visual programming language, program logic formulation, pseudocode, flowcharts, and the input-process-output (IPO) model. They provide a structured approach to understanding and designing computer programs.

Full Transcript

SCRATCH Sunday, 8 September 2024 7:54 pm SCRATCH What is Scratch 3.0 ► A block-based visual programming language that introduces basic programming concepts through interactive and engaging projects. ► Developed by MIT Media Lab, first released in 2007 Why is Scratch 3.0 ► Logical think...

SCRATCH Sunday, 8 September 2024 7:54 pm SCRATCH What is Scratch 3.0 ► A block-based visual programming language that introduces basic programming concepts through interactive and engaging projects. ► Developed by MIT Media Lab, first released in 2007 Why is Scratch 3.0 ► Logical thinking and problem-solving skills ► Understanding fundamental programming concepts ► Creativity and collaboration Program Logic Formulation and Computer Programming Page 1 Program Logic Formulation Tuesday, 27 August 2024 8:23 am PROGRAM LOGIC FORMULATION - The process of designing and structure the sequence of operations (logic) that a computer program will follow to achieve a specific goal or solve a particular problem. PROGRAM - A set of instruction that or the execution to perform a specific task or solve a problem. - A sequence of commands or instructions that directs a computer to perform a series of operations. - A systematic plan of action that involves a step-by-step process of resolving a problem. LOGIC - formal principle of reasoning, particularly in the context of computer program, where it dictates how a program evaluates conditions and makes decisions. - the foundational structure that allows program to perform reasoning task,.. SYSTEM - A collection of interconnected components that works together to achieve a specific function or set of functions, typically involving both hardware and software. - An organized collection of components or modules that are designed to work together to provide a specific service or set of services to users. ALGORITHM - A step-by-step procedure or formula for solving a problem or competing a task. It consist pf finite set of instruction that, when executed, performs a particular function. DEBUGGING - The process of finding and fixing errors or bugs in a program. It is an essential part of program logic formulation, ensuring that the the logic is implemented correctly. 1. Identify the bug 2. Isolate the source of the bug 3. Fix the bug 4. Test the program to ensure the bug is resolved Program Logic Formulation and Computer Programming Page 2 PSEUDOCODE Tuesday, 27 August 2024 8:32 am What is PSEUDOCODE? - a step by step description of an algorithm - uses the simple English language text as it is intended for human understanding rather than machine reading -the intermediate state between an idea and its implementation (code) - follow certain rules - pseudo (fake) - bridge between algorithm and program Why PSEUDOCODE Simplification - break down complex problems into manageable steps. By writing out the logic in plain language, it becomes easier to understand and solve the problem. Planning - helps the designing the structure and flow of the program. Early Debugging - allows identification of potential errors and issues early in the development process. Transition - ease of transition into any programing language Syntax - set of rules and conventions to write the pseudocode in a clear and understandable manner. Statement - an instrument that direct the computer to perform a specific action. One line per statement. Keyword - reserved words that have predefined meaning, serve as building blocks and helps in defining the syntax and structure of a program. Identification - shows the hierarchy and structure of the code, especially within loops and conditional statements. This helps in understanding the flow of the algorithm Comments - used to explain parts of the pseudocode. Comments are usually prefixed with \\ Keywords _____________________________________________________ SEQUENCE ~ Input: READ, OBTAIN, GET Output: PRINT, DISPLAY, SHOW Compute: COMPUTE, CALCULATE, DETERMINE Initialize: SET, INIT Add: INCREMENT, BUMP Sub: DECREMENT _____________________________________________________ FOR ~ FOR iteration bounds sequence ENDFOR _____________________________________________________ WHILE ~ WHILE condition sequence ENDWHILE _____________________________________________________ CASE ~ CASE expression OF Program Logic Formulation and Computer Programming Page 3 CASE expression OF condition 1: sequence 1 condition 2: sequence 2.. condition n: sequence n OTHERS: default sequence ENDCASE _____________________________________________________ REAPEAT ~ REAPEAT sequence UNTIL condition _____________________________________________________ IF-THEN-ELSE ~ IF condition THEN sequence 1 ELSE sequence 2 ENDIF RULES - Write only one stmt (statement) per line - Capitalize initial keyword - Indent to show hierarchy - End multiline structure - Use proper naming conventions - Keep it simple and concise Program Logic Formulation and Computer Programming Page 4 FLOWCHART Tuesday, 27 August 2024 8:35 am What is a FLOWCHART? - a graphical representation of a process or algorithm, showing the sequence of steps using standardized symbols. - visualizing the flow of control in a program or process, making it easier to understand, communicate, and debug complex logic. Why FLOWCHART Simplification - Flowcharts break down complex processes into manageable steps Communication - They are useful for explaining processes to others, especially non-technical stakeholders. Problem-Solving - Flowcharts are a valuable tool in debugging, allowing you to trace the flow of program or process to identify errors. Documentation - Flowcharts serve as a form of documentation, preserving the logic of a process for future reference. FLOWCHARTS SYMBOLS TERMINAL SYMBOL - the oval symbol indicates the beginning or end of a flowchart. It is also used in pausing of logic flow. Pausing, often utilized during error condition, helps control the program's logic. INPUT/OUTPUT SYMBOL - Indicates the process of inputting or outputting external data. This is indicated by the shape of a parallelogram. It is used to depict program instructions that gather input from input devices and presents output on output devices. PROCESS SYMBOL - Represent a step in a process. Represented by a rectangle, it signifies an action or operation performed in the flowchart. DECISION SYMBOL - Represented by a diamond shape, it signifies a decision point in the process where a choice must be made, loading to a different paths based on certain conditions. Choices can be yes/no questions or true/false conditions. FLOWLINE SYMBOL - Shows the process' direction. Each flowline connects two blocks. Arrows represent the direction of flow of control and relationship among different symbols of flowchart. CONNECTOR SYMBOLS - Whenever flowchart becomes complex or it spreads over more than one page, it is useful to use Program Logic Formulation and Computer Programming Page 5 CONNECTOR SYMBOLS - Whenever flowchart becomes complex or it spreads over more than one page, it is useful to use connectors to avoid any confusions. On-page connectors are represented by a circle while off-page connectors are represented by a semi-square, containing an arrow-like shape at the bottom. COMMENT SYMBOL- Indicates additional information regarding a step in a process. - Program Logic Formulation and Computer Programming Page 6 IPO Sunday, 8 September 2024 10:50 pm Input-Process-Output (IPO) model a conceptual framework used to describe and understand the functioning of systems, particularly in fields like computer science, engineering, and business analysis. outlines the flow of information and actions within a system breaks down into three main components: Input, Process, and Output. Why IPO ► CLARITY AND COMMUNICATION ○ it provides a structured and clear way to represent the flow of information and actions within a system. ► REQUIREMENTS ANALYSIS ○ to have a deep understanding of the inputs required and the desired outputs. ► LOGIC AND ALGORITHM DEVELOPMENT ○ teaches the actual manipulation and transformation of input data to generate the desired outputs. ► MODULAR DESIGN ○ each component can be treated as a separate module, making it easier to manage, test, and update individual parts without affecting the entire system. ► SYSTEM EVALUATION ○ provides a framework for evaluating system performance and effectiveness. INPUT ► Data or materials entered into a system to be processed. ► can come from various sources and are essential to initiate the process Process ► The steps or actions taken to transform the input into a result ► the input data is manipulated, transformed, or processed in some way to achieve a desired outcome ► involves various operations, calculations, algorithms, and logic Output ► the final product or result generated after the processing ► the transformed or processed data after applying the necessary operations Program Logic Formulation and Computer Programming Page 7 Program Logic Formulation and Computer Programming Page 8 PYTHON Sunday, 8 September 2024 11:11 pm PYTHON History of Python created by Guido van Rossum. Named after BBC TV Show "Monty Python's Flying Circus" to reflect the fun nature of the language development began in the late 1980s at the Centrum Wiskunde & Informatica (CWI) in the Netherlands laid its foundation in 1989 first release, version 0.9.0, came out in February 1991 Python 1.0 was released in January 1994 Python continued to evolve, with Python 2.0 released in October 2000 December 2008-Present - Python 3.0 Features of Python ► Python is an interpreted language, which means that code is executed line by line allowing for easy debugging and immediate feedback. ► Python is dynamically typed, meaning there is no need to declare the data type of a variable when you create it. The type is determined at runtime. ► Python supports object-oriented programming (OOP), which allows developers to create classes and objects, enabling modular and reusable code. ► Python is a high-level language yet simplifies intricate information or concepts into more understandable and concise forms allowing for developers to focus more on logic. Why Python ► READABILITY AND SIMPLICITY - Python's syntax is designed to be clean and easy to read ► VERSATILITY - Python is a general-purpose language that can be used for a wide range of applications, including web development, data science, artificial intelligence, scientific computing, automation, and more. ► LARGE COMMUNITY AND LIBRARIES - Python has a vast and active community ► CROSS-PLATFORM - Python is platform-independent, meaning it can run on various operating systems like Windows, macOS, and Linux without modification. Development Environment of Python IDE (Integrated Development Environment) - software application that provides comprehensive tools and features to assist developers in writing, debugging, and deploying software. Text Editors are simple programs that are typically included with most operating systems that only allows basic text editing operations. How are Python programs executed? 1. Source Code - Start by writing the Python code in a file with a.py extension. 2. Tokenization - An interpreter reads the source code and breaks it down into smaller units called tokens. 3. Parsing - The interpreter then parses these tokens to create a data structure called the Abstract Syntax Tree (AST). 4. Translation - The interpreter then translates the AST into bytecode. Program Logic Formulation and Computer Programming Page 9 4. Translation - The interpreter then translates the AST into bytecode. 5. Execution - The bytecode is executed by the Python Virtual Machine. 6. Result - As the bytecode is executed, the Python program performs its intended actions. VARIABLES AND DATA TYPES What are Variables? variable_name = value age = 22 name = "John" height = 5.9 ► Variables are storage or containers for storing data values. ► It behaves whatever the value it contains. ► The stored data can be manipulated and retrieved. ► Variables are case-sensitive. Rules: # acceptable var = "John" varname = "John" VarName = "John" VARNAME = "John" _var_name = "John" varname2 = "John" # NOT acceptable 2var = "John" var-name = "John" var name = "John" 1. Must start with a letter or an underscore (_) 2. Cannot start with a number 3. Can only contain alpha- numeric characters and underscores (A-z, 0-9, and _) 4. Case-sensitive (e.g., age, Age, and AGE are different variables) 5. cannot be any of the Python keywords (e.g., and, for, is) Naming Styles: ► Camel Case - Each word, except the first, starts with a capital letter myVariablellame = "John" ► Pascal Case - Each word starts with a capital letter MyVariableName = "John" ► Snake Case - Each word is separated by an underscore my_variable_name = "John" BASIC DATA TYPES # integer Program Logic Formulation and Computer Programming Page 10 # integer age = 22 # float height = 5.9 # string name = "John" # boolean is_student = True Integer (int): Whole numbers, e.g., 1, -2, 42 Float (float): Decimal numbers, e.g., 3.14, -0.01, 2.0 String (str): Sequence of characters, e.g., "Hello, World!", 'Python' Boolean (bool): True or False type() function - get the data type Enter INPUT AND OUTPUT username = input("Enter username: ") print("Username: " + username) print("Username:", username) print(f"Username: {username}") Python allows for user input using the input() function. For output, we have the print() function. Program Logic Formulation and Computer Programming Page 11

Use Quizgecko on...
Browser
Browser