KEMBAR78
Comprog Reviewer Midterm 1 | PDF | Algorithms | Python (Programming Language)
0% found this document useful (0 votes)
10 views9 pages

Comprog Reviewer Midterm 1

The document outlines the programming cycle, which includes problem definition, planning, design, coding, testing, and debugging, emphasizing the importance of structured development and quality assurance. It introduces key programming concepts such as algorithms, pseudocode, and flowcharts, along with the benefits of using Python as a programming language for various applications including web development, scientific computing, and education. Additionally, it discusses Python's unique features, data types, and variable naming conventions, highlighting its readability and ease of use.

Uploaded by

azielairont
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views9 pages

Comprog Reviewer Midterm 1

The document outlines the programming cycle, which includes problem definition, planning, design, coding, testing, and debugging, emphasizing the importance of structured development and quality assurance. It introduces key programming concepts such as algorithms, pseudocode, and flowcharts, along with the benefits of using Python as a programming language for various applications including web development, scientific computing, and education. Additionally, it discusses Python's unique features, data types, and variable naming conventions, highlighting its readability and ease of use.

Uploaded by

azielairont
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

▪​ Sequence – it involves arranging

LESSON 2: Programming Logic Design


instructions in a specific order to
and Formulation
achieve the desired outcome.
PROGRAMMING CYCLE ▪​ Conditional Statements – these
are statements enable the program
​ also known as the software
to make decisions based on certain
development cycle or the coding conditions.
cycle
▪​ Loops and Iteration - these are
​ refers to the iterative process that
used to execute a set of instructions
programmers follow when creating repeatedly.
software applications.
▪​ Variables and Data - it involves
​ It encompasses the steps involved in
working with variables to store and
writing, testing, and refining code to manipulate data.
achieve the desired functionality.
▪​ Logical Operators – these are
The Key Aspects of Programming cycle:
logical operators (AND, OR, NOT)
enable programmers to combine
▪​ Problem Definition and Analysis
conditions and make complex
▪​ Planning decisions based on multiple criteria
▪​ Functions and Procedures - it
▪​ Design
involves organizing code into
▪​ Coding functions and procedures, which are
blocks of code that can be reused
▪​ Testing throughout the program
▪​ Debugging ▪​ Error Handling – these are
▪​ Optimization handling errors and exceptions is
essential to ensure that the program
▪​ Documentation gracefully manages unexpected
situations without crashing.
▪​ Refining and Iteration
▪​ Algorithm Design - involves
▪​ Deployment and Maintenance breaking down complex tasks into
smaller, manageable steps.
Benefits of the Programming Cycle
Importance of Programming
▪​ Structured Development Language

▪​ Quality Assurance ●​ Accuracy


●​ Efficiency
▪​ Adaptability ●​ Debugging
●​ Readability and Maintainability
▪​ Efficiency
Example of Programming Logic
PROGRAMMING LOGIC

​ refers to the systematic and structured


approach that programmers use to
develop algorithms and solve problems
using code.
Key Concepts in Programming Logic
ALGORITHM
Example of Pseudocode
​ is a step-by-step set of instructions
designed to solve a specific problem or
perform a particular task.
​ It's a clear and unambiguous sequence
of actions that, when followed correctly,
leads to the desired outcome.
(Algorithms are used in various fields,
including computer science, mathematics,
and engineering, to solve complex problems
efficiently.) FLOWCHART
Key Characteristics of Algorithms:
​ a visual representation of the sequence
▪​ Well-Defined of steps and decisions involved in a
process or algorithm.
▪​ Input and Output
​ It uses standardized symbols and
▪​ Finiteness arrows to depict the flow of control in a
clear and easily understandable
▪​ Effectiveness
manner.
▪​ Deterministic (Flowcharts are widely used to visualize
complex processes, algorithms, and
Example Algorithm workflows.)
1.​ Read the first number as fNum.
Flowchart Symbols
2.​ Read the second number as
sNum.
3.​ If fNum is greater than sNum,
assign fNum to max
4.​ Otherwise, assign sNum to max
5.​ Print max as the maximum
number.
PSEUDOCODE

​ an informal way to express algorithms


using a combination of human-readable
programming language-like constructs
and natural language descriptions.
​ It provides a high-level description of the
​ Example Flowchart
algorithm's logic without getting into the
specifics of actual programming syntax.
Benefits of Pseudocode

▪​ Readability

▪​ Flexibility

▪​ Clarity​
about lately: a descendant of ABC that
would appeal to Unix. He chose Python as a
working title for the project, being a big
Monty Python’s flying circus (A Sketch
Comedy Group Series) Fan.
Benefits of Flowchart

▪​ Visual Representation

▪​ Clarity

▪​ Communication

▪​ Analysis

▪​ Documentation

​ Flowchart Considerations
●​ Clarity
●​ Simplicity
Why Was Python Created?
●​ Consistency
●​ Testing
"My original motivation for creating Python
was the perceived need for a higher-level
LESSON 3: Computer Program Basics language in the Amoeba [Operating
using​ Systems] project. I realized that the
PYTHON development of system administration
utilities in C was taking too long. Moreover,
doing these things in the Bourne shell
PYTHON
wouldn't work for a variety of reasons. ... So,
​ an interpreted high-level programming there was a need for a language that would
bridge the gap between C and the shell” ​
language for general-purpose
programming. ​ ​ ​ ​ ​ ​
- Guido Van Rossum
​ Created by Guido van Rossum and first
released in 1991
Uses and Application of Python
​ Python has a design philosophy that
▪​ Web and Internet Development:
emphasizes code readability, notably
using significant whitespace. Python lets you develop a web
application without too much
​ It provides constructs that enable clear
trouble. It has libraries for internet
programming on both small and large
protocols like HTML and XML,
scales.
JSON, e-mail processing, FTP,
​ In July 2018, the creator Guido Rossum IMAP, and easy-to-use socket
stepped down as the leader in the interface. Yet, the package index
language community after 30 years.
has more libraries
Van Rossum, was looking for a "hobby" ▪​ Scientific and Numeric
programming project that would keep him
Applications: This is one of the
occupied during the week around Christmas.
His office ... would be closed, Hence he very common applications of python
decided to write an interpreter for the new programming. With its power, it
scripting language he had been thinking comes as no surprise that python
finds its place in the scientific ●​ It's portable - Python runs virtually
community. every major platform used today, As
long as you have a compatible
▪​ Python Applications in Python interpreter installed, Python
Education: Thanks to its simplicity, programs will run in exactly the
same manner, irrespective of
brevity, and large community,
platform.
Python makes for a great ●​ Readability - Python's syntax is
introductory programming language. clear and readable. The way
Applications of python programming Python's syntax is organized
in education has huge scope as it is imposes some order to
a great language to teach in schools programmers. Experts and
or even learn on your own. beginners can easily understand the
code, and everyone can become
▪​ Games and 3D Graphics: productive in Python very quickly.
●​ It Is Simple to Get Support - The
PyGame, PyKyra are two
Python community always provides
frameworks for game-development support to Python users. As we
with Python. Apart from these, we already know, Python code is freely
also get a variety of 3D-rendering available for everyone. Therefore,
libraries. thousands of developers worldwide
are working hard to find bugs and
▪​ Software Development create patches to fix those bugs.
Application: Software developers ●​ Reusability - Python encourages
make use of python as a support program reusability by implementing
language. They use it for modules and packages. A large set
build-control and management, of modules has already been
testing, and for a lot of other things developed and is provided as The
Standard Python Library, which is
▪​ Business Applications: Python is
part of the Python distribution. You
also used to build ERP and can easily share functionality
e-commerce systems. between your programs by breaking
the programs into modules and
In Conclusion, Python is almost reusing the modules as components
everywhere and now that we know Python of other programs.
applications. We can do with it, we feel more DIFFERENCE OF PYTHON FROM OTHER
powerful than ever. LANGUAGES
●​ Python code does not declare the
Why Do People Use Python? types of variables -- just assign to
them and go.
●​ Python is object-oriented - ●​ Python raises a runtime error if the
Structure supports such concepts as code tries to read from a variable
polymorphism, overloading, and that has not been given a value.
multiple inheritance. ●​ Like C++ and Java, Python is case
●​ It's free (open source) - sensitive so "a" and "A" are different
Downloading and installing Python variables.
is free and easy Source code is ●​ The end of a line marks the end of a
easily accessible. statement, so unlike C++ and;
●​ It's powerful - Dynamic typing, ●​ Java, Python does not require a
Built-in types and tools, Library semicolon at the end of each
utilities, Third-party utilities (e.g. statement.
Numeric, NumPy, SciPy), Automatic ●​ You can include semicolons at the
memory management end of Python statements (perhaps
just out of habit), but it's not the best
▪​ But, tuples are fixed in size once
style.
●​ Comments begin with a '#' and they are assigned. In Python the
extend to the end of the line. fixed size is considered immutable
as compared to a list that is dynamic
Python Data Types
and mutable.
1.​ Number Python
▪​ Tuples are defined by parenthesis
▪​ Numbers variables are created by
().
the standard Python method.
▪​ Most of the time using the standard 5.​ Dictionary
Python number type is fine. ▪​ Dictionaries in Python are lists of
▪​ Python will automatically convert a Key: Value pairs.
number from one type to another if it ▪​ This is a very powerful datatype to
needs. But, under certain
hold a lot of related information that
circumstances where a specific
can be associated with keys.
number type is needed (ie. complex,
hexadecimal), the format can be ▪​ The main operation of a dictionary is
forced into a format by using to extract a value based on the key
additional syntax. name.
2.​ String
▪​ Unlike lists, where index numbers
▪​ Create string variables by enclosing
are used, dictionaries allow the use
characters in quotes. of a key to access its members.
▪​ Python uses single quotes ' ▪​ Dictionaries can also be used to
double quotes " and triple quotes sort, iterate, and compare data.
""" to denote literal strings.
▪​ Dictionaries are created by using
▪​ Only the triple quoted strings """ also
braces ({}) with pairs separated by a
will automatically continue across comma (,) and the key values
the end-of-line statement associated with a colon (:). In
3.​ List Dictionaries, the Key must be
▪​ Lists are a very useful variable type unique.
Keywords In Python
in Python.
​ Print: print to console
▪​ A list can contain a series of values.
List variables are declared by using ​ While: controlling the flow of the
brackets [ ] following the variable program
name.
​ For: iterate over items of a collection
4.​ Tuple
so that they appear
▪​ Tuples are a group of values like a
​ Break: interrupt the (loop) cycle, if
list and are manipulated in similar
ways. needed
•​ Python can be used alongside software
​ Continue: used to interrupt the
to create workflows.
current cycle, without jumping out of •​ Python can connect to database
the whole cycle. A new cycle will systems. It can also read and modify
begin. files.
​ If: used to determine, which •​ Python can be used to handle big data
and perform complex mathematics.
statements are going to be executed.
•​ Python can be used for rapid
​ Elif: stands for else if.If the first test prototyping, or for production-ready
evaluates to False, then it continues software development.
with the next one
Python is an interpreted programming
​ Else: is optional. The statement after
language, this means that as a developer
the else keyword is executed, unless you write Python (.py) files in a text editor
the condition is True and then put those files into the Python
​ Is: tests for object identity interpreter to be executed.
​ Python Syntax: can be executed by
​ Not: negates a boolean value
writing directly in the Command Line.
​ Or: at least one condition must be
​ Python Indentation: refers to the
met.
spaces at the beginning of a code line.
​ Import: import other modules into a Where in other programming languages
Python script the indentation in code is for readability
only, the indentation in Python is very
​ From: for importing a specific
important.
variable, class, or function from a
▪​ Python uses indentation to
module
indicate a block of code.
​ Def: used to create a new
▪​ The number of spaces is up to
user-defined function
you as a programmer, the most
​ Return: exits the function and
common use is four, but it has to
returns a value be at least one
​ Global: access variables defined ​ Python Variables: In Python, variables
outside functions are created when you assign a value to
​ Try: specifies exception handlers it:
▪​ Variables do not need to be
​ Except: catches the exception and
declared with any particular type
executes codes and can even change type after
​ Finally: is always executed in the they have been set.
end. Used to clean up resources.
What can Python do? ​ Casting: If you want to specify the data
•​ Python can be used on a server to type of a variable, this can be done with
create web applications. casting.
​ Comments: Python has a commenting ▪​ Camel Case: Each word,
capability for in-code documentation. except the first, starts with a
Comments start with a #, and Python capital letter.
will render the rest of the line as a ex. myVariableName = "John"
comment.
▪​ Pascal Case: Each word starts
▪​ Comments can be placed at the with a capital letter.
end of a line, and Python will ex. MyVariableName = "John"
ignore the rest of the line.
▪​ Snake Case: Each word is
​ Variable Names: A variable can have a separated by an underscore
short name (like x and y) or a more character.
descriptive name (age, carname, ex. my_variable_name = "John"
total_volume).
Rules for Python variables:
▪​ A variable name must start with
Assign Multiple Values
a letter or the underscore
character ▪​ Python allows you to assign
values to multiple variables in
▪​ A variable name cannot start
one line:
with a number
▪​ A variable name can only
contain alpha-numeric
characters and underscores
(A-z, 0-9, and “_” )
Note: Make sure the number of
▪​ Variable names are
variables matches the number of
case-sensitive (age, Age, and values, or else you will get an error.
AGE are three different
variables) One Value to Multiple Variables
▪​ A variable name cannot be any ▪​ And you can assign
of the Python keywords.

the same value to multiple


variables in one line:
​ Multi Words Variable Names: Unpack a Collection

Variable names with more than one ▪​ If you have a collection of


word can be difficult to read. values in a list, tuple etc. Python
There are several techniques you can allows you to extract the values
use to make them more readable:
into variables. This is can add an * to the variable
called unpacking. name and the values will be
assigned to the variable as a
list:
Example

​ Packing a Tuple

▪​ When we create a tuple, we


normally assign values to it.
This is called "packing" a tuple:
LESSON 4: Computer Program Basics
Example
using​
PYTHON
​ fruits = ("apple", "banana", "cherry")

PYTHON DATA TYPES


​ In programming, data type is an
​ Unpacking a Tuple
important concept.
▪​ We are also allowed to extract
the values back into variables. ​ Variables can store data of different
This is called "unpacking":
types, and different types can do
Example
different things.

Python has the following data types


built-in by default, in these categories:
Getting the Data Type
▪​ You can get the data type of any object

​ Using Asterisk by using the type() function:

▪​ If the number of variables is less


than the number of values, you

Setting the Data Type


▪​ In Python, the data type is set when
you assign a value to a variable:
▪​ Float or "floating point number": is
a number, positive or negative,
containing one or more decimals.

▪​ Complex: Complex numbers are


written with a "j" as the imaginary
part.

Python Numbers

▪​ Int

▪​ float

▪​ complex Type Conversion


You can convert from one type to another with
the int(), float(), and complex() methods:

​ Variables of numeric types are created


when you assign a value to them:

​ To verify the type of any object in Python,


use the type() function.
Python Numbers:
▪​ Int or integer: is a whole number,
positive or negative, without
Random Number
decimals, of unlimited length.
●​ Python does not have a random() function
to make a random number, but Python has
a built-in module called random that can be
used to make random number.

You might also like