Programming & Data Manipulation
Programming & Data Manipulation
200IE-3
Chapter 1 – Fundamentals of
Programming Language
200IE-3 Data Inputs& Manipulation
200-IE-2 Data Inputs & Manipulation-Syllabus
Course Title Data Inputs& Manipulation
• Contents Course Code 200-IE-2
• 1. Fundamentals of No. of Units (Theoretical + Tutorial/Lab)
Level/ Year
3(2+1)
4/2
Programming
Languages. General Structure
Prerequisite (if any)
of C Programming
Language/Python Course Assessment Python Companies
I. Quiz 15%
• 2. File I/O. String Processing, Variables
II. Assignment 15%
and
Sequences.Operations,
If Basic I/O Switch
III. Mid Exams 20%
Functions, Statement,
Statement, Loops, IV. Final Exam 40%
Functions. Loops, Nested V. Lab./Tutorial 10%
• 3. HTML, CSS, Web Scraping, Writing Teaching Methods
HTML and Basic Interfacing with SQL I. Lectures
Databases (Reading/Writing Data in II. Group Discussion
III. Study Assignments
Pre-existing Tables) IV. Interacting through E-learning
• 4. Software for Commercial V.
VI.
Lab. Experiments / Tutorial
Project & Trend Study
HTML: Hypertext Markup Language
5
Objectives
• Data Input & Manipulation
• Coding & Software Languages
• Difference in C & Python https://www.python.org/downloads/
• Role of MySQL
• Role of HTML
• Introduction to Python
• Basic Language Concepts
6
https://www.jetbrains.com/pycharm/download/#section=windows
Data Input & Manipulation
• Data Input:
• A computer file that contains data that serve as input to a device or
program. Any information or data sent to a computer for processing is considered
input. Input or user input is sent to a computer using an input device.
• Data Manipulation:
• A Data Manipulation Language (DML) is a family of computer
languages including commands permitting users to manipulate data in a Database
(DB).
• This manipulation involves inserting data into database tables,
retrieving existing data, deleting data from existing tables and modifying existing
data.
• Or
• Data Manipulation includes Add, delete, modify, and retrieve records from a
Database. CRUD: Create, Read, Update, and Delete
• High-Level Language (HLL):
• A high-level language is any programming language that enables
development of a program in a much more user-friendly programming context
and is generally independent of the computer's hardware architecture.
Example: Java, C, C++, Python, etc.
• Low-Level Languages (LLL):
• Low-level languages are designed to operate and handle the entire
hardware and instructions set architecture of a computer directly.
• Assembly Language:
•
• For Example:
An assembly ADD [result],[coursework],[exam]
language is a low-level programming language for microprocessors and other
• The most commonly
programmable devices. It isused assembly
not just languages
a single language, include
but rather ARM,
a group MIPS, and x86.
of languages. 7
Programming Languages: Role
8
Coding & Software Languages:
What & Why?
• iOS App – Swift
• Android App - Java, Kotlin
• Websites –
• Frontend: HTML, CSS, JS
• Backend: node JS, django
• PHP (for old apps)
• Data Science – Python, R, MATLAB
• Game Development – C++, C# (C Sharp)
• Software Development – Java, C#, Golang
• Fun – Python, Java
9
Programming Languages (Contd)
• Programming
• Programming is the process of creating a set of instructions that tell a computer how to perform a task. Programming can be done
using a variety of computer programming languages, such as JavaScript, Python, and C++.
• Programming Language
• A programming language is a type of written language that tells computers what to do. Programming languages are used to write
all computer programs and computer software.
• Examples: Python, Ruby, Java, JavaScript, C, C++, and C#.
• Fundamental Concepts of Programming Languages
• Basic Syntax
• Variable Declaration
• Data Type and Structures
• Flow Control Structures
• Conditions & Loops
• Functional Programming
• Object-Oriented Programming
• Debugging
• IDEs and Coding Environments
• Text Editor
• Interpreter
• Compiler
• Assembler
• Debugger
• Simulator
• Warning
• Error
11
Programming Language - Python
• Python Programming Language
• Python is an interpreted, high-level, object-oriented, and
general-purpose programming language with dynamic
semantics. Its design philosophy emphasizes code
readability with the use of significant indentation.
• It was designed and developed by Guido van Rossum and
was originally released in 1991.
12
C & Python Language
C Python
for loop, while, do-while loop, switch for loop, while loop
statement, pointers
Suitable for system software, Suitable for ML, AI, Data Science
firmware
13
Programming Language – SQL
• SQL & MySQL:
• SQL is a Programming Language that can be used to work with data in databases, while MySQL is an Open-
Source Database product that implements the SQL standard.
• MySQL:
• MySQL is a Relational Database Management System (RDBMS) developed by Oracle that is based on
Structured Query Language (SQL) . MySQL is a Database Management System (DBMS). A database is a
structured collection of data. It may be anything from a simple shopping list to a picture gallery or a place to
hold the vast amounts of information in a corporate network.
• To add, access, and process data stored in a computer database, a Database Management System (DBMS)
such as MySQL Server is needed.
• MySQL works very well in combination with various programming languages like PERL, C, C++, JAVA, and PHP.
• NOTE: Out of these languages, PHP is the most popular one because of its web application development
capabilities.
• Why MySQL?:
• MySQL is a Relational Database Management System (RDBMS) that offers a variety of features, including,
tables, rows, columns, and indexes. MySQL is ideal for storing application data, specifically web application
data.
• MySQL allows to perform database operations on these tables, rows, columns, and indexes.
• Tables (collection of rows and columns), also known as relations, are used to construct database relationships.
• What are the benefits of MySQL?
• Data Protection.
• It is one of the most popular database management systems in terms of security and dependability.
• Scalability on Demand.
• High Efficiency.
• 24/7 Uptime.
• Outstanding Transactional Support.
• Excellent Workflow Control.
• Lower Total Ownership Cost. 14
Markup Language: HTML
• Hyper Text Markup Language (HTML)
• It's a markup language. HTML is not a programming language.
• It encapsulates, or “marks up” data within HTML tags, which
define the data and describe its purpose on the webpage.
• NOTE: The markup text could come in the form of boldface or italicized
type to draw specific attention to a word or phrase.
• The web browser then reads the HTML, which tells it things like
which parts are headings, which parts are paragraphs, which
parts are links, etc.
• HTML defines the structure of webpages, and it determines
how data is displayed online.
• What you’re looking at right now is HTML code,
read and
interpreted by your browser.
• Cascading Style Sheets (CSS)
• Cascading Style Sheets is a style sheet language
used for describing the presentation of a document
written in a markup language such as HTML or XML
(WWW), alongside
(Extensible MarkupHTML and
Language). CSS is a cornerstone 15
Development of Python: Introduction
• Guido Van Rossum, a Dutch programmer best known as the author of the Python
Programming language. He developed Python in 1991 as an easy fun to do programming language.
For this he was the "Benevolent Dictator for Life" until he stepped down from the position in July
2018.
• Python Introduction:
• Python is a high-level, interpreted, general-purpose, and dynamic programming language that focuses on
code readability. Professionally, Python is great language for the backend web development, data analysis,
artificial intelligence, and scientific computing.
• The syntax in Python helps the programmers to do coding in fewer steps as compared to Java, C, or C++.
• Python is widely used in bigger organizations because of its multiple programming paradigms.
• They usually involve imperative and object-oriented functional programming.
• It has a comprehensive and large standard library that has automatic memory management and
dynamic features.
• Many Software Developers have also used Python to build the productivity tools (Calculator, Calendar, etc.),
• What language
games, is “Python”
and desktop apps. written in?
• Since most modern OS, compilers/interpreters for modern high-level languages are written in C. Guido van
• Python is not an exception. Rossum
• Its most popular/"traditional" implementation is called CPython and is written in C.
• There are other Python implementations: IronPython (Python running on .NET). 16
Why Companies Prefer Python? (Contd)
• The software development companies prefer Python language because of its versatile features and fewer programming
codes. Nearly 14% of the programmers use it on the operating systems like UNIX, Linux, Windows and MacOS.
• The programmers of big companies use Python in software development as it has characteristic features like:
• Interactive
• Interpreted
• Modular
• Dynamic
• Object-oriented
• Portable
• High level
• Extensible in C++ & C
• Easy-to-learn
• Easy-to-read
• Easy-to-maintain
• Robust
• Effective as a Rapid Prototyping Tool
• A Memory Manager
• Interpreted and (Byte) Compiled
17
Compilers and Interpreters
• Compiler & Interpreter
• Its a translator used to convert HLL to MLL and vice versa.
18
Python Distribution
• Working in Python
• Python is Free, Open-Source Software (FoSS) that works on
Linux, Mac, Windows, and various other platforms (21 in
total).
• It comes pre-installed on Mac and most distributions of Linux.
• There are multiple python distributions available.
• Python Distribution
• A Python distribution is a software bundle, which contains a
Python interpreter and the Python standard library.
• Example:
• PyCharm: It is an IDE built to make it easier to write Python code, by
providing a text editor and debugging, among other features.
• Anaconda: It is a Python distribution focused on data driven projects.
• NOTE: Both PyCharm and Anaconda tools are popular with businesses of
all sizes that use Python. 19
Integrated Development Environment (IDE)
• IDE
• An Integrated Development Environment (IDE) is a
software application that provides comprehensive
facilities to computer programmers for software
development.
• An IDE normally consists of a
• Editor (source code editor),
• Compiler (Build Tool) and
• Debugger.
• Most modern IDEs have
intelligent code completion.
• Python IDE / IDLE
• Integrated Development Environment (IDE) /
Integrated Development and Learning
Environment (IDLE) is an integrated
development environment for Python which has
been
Pythonbundled with
shell with the highlighting.
syntax default implementation 20
of the language since 1.5.2b1. It has
Python Basic Modes: Shell & Script
• Python Shell / Python Interactive Shell
• Python offers a comfortable command line interface with
the Python shell, which is also known as the "Python
Interactive Shell".
• Script
• A script is a text (.txt) file containing the statements that
comprise a Python program. Scripts are editable and reusable.
• Once a script has been created, it can be run/execute over and
over without having to retype it each time.
• What are the basic modes of python?
• Python has TWO Modes
• 1. Script Mode
• This is the normal mode where the scripted and finished .py
files are run in the Python interpreter.
• 2. Interactive Mode
• This is a command line shell (>>>) which gives immediate
feedback for each statement, while running previously fed
statements in active memory.
• Python “Hello World” Program: Shell/IDE
• Write the Python Program for “Hello World” using Python
Shell/IDE
• Using Python Script – file name “my_name_id.py”
• Using Interactive Mode – at the Command Prompt 21
#Flow Chart-EVEN or ODD
Number a=int(input("Enter
Flowchart A:"))
if a%2 == 0:
print("EVEN")
else:
print ("ODD")
• Flowchart
• Flowchart is the Graphical Representation of an algorithm. It is
used to show all the steps of an algorithm in a sequence pictorial
shapes.
• An algorithm may be converted to a flowchart.
• The flowchart is then converted into a program written in
any programming language.
• Advantages of Flowcharts
• 1. Flowchart represents an algorithm using graphical symbols.
• 2. It shows the steps of an algorithm in an easy way.
• 3. It is used to understand the flow of the program graphically.
• 4. Flowchart can be easier and more effective to understand the
logic of the given program instantly.
• 5. A flowchart will be helpful to the programmer during coding /
program development phase.
22
Flowchart (Contd)
• Flowchart (Contd)
• Commonly Used Symbols To Draw a Flowchart
• 1. Start/End
• Oval symbol is used to represent the start or end of the flowchart. Every program has a Start and End. So, we will add an Oval
symbol with caption "Start" in the beginning of each flow chart. Similarly, we will place an Oval symbol
with the tag "End" or "Stop" at the end of every flow chart.
• 2. Input/Output
• Parallelogram symbol is used to represent an input or output step. So, if we wish to input the value of a variable N in our
program, we will put a parallelogram symbol there with a caption of "Input N" or "Read N" etc.
Similarly, we will use this symbol to represent output statements in program too. For Example, if we encounter an
output statement in our program algorithm to show a message "Enter a Number:", we will add a parallelogram
symbol with the caption "Enter a Number". If we wish to show the value of a variable, we may add parallelogram
symbol with the text "The result =", result. Where "result" is a variable name.
• 3. Process
• Rectangle symbol is used to represent a process step. A process may be a calculation or assignment etc. The algorithmic
statements like Calculate Sum = Num1 + Num2 can be represented by the rectangle symbol in
flowcharts. Similarly, the assignment statements like Width = 10 may also be represented by rectangle symbol.
• 4. Selection/Decision
• Diamond symbol is used to represent a selection step. A condition is given in the diamond. If condition is true, then flow of
control will go in one direction. If condition is false, then control will go in other direction.
• 5. Flow Lines
• Arrow symbols are used to represent the direction of control flow. There are four types of flow lines.
• 6. Connector/Join/Combine
• Circle symbol is used to combine different flow lines. It is used as a connector symbol in flow charts.
23
Example2: Develop
Flowchart (Contd) a
flowchart to input 5
numbers from the user,
calculate its average and
• Example1: Develop a then display the result.
flowchart to input two
numbers from the user, Answer:
calculate its sum and Start
then display the result. Input: User Inputs A, B, C,
• Answer: D, E Process1: Total=
• Start A+B+C+D+E Process2:
• Input: User Inputs X, Y Average=Total / 5 Output:
• Process: SUM = X + Y Display Average
• Output: Display SUM End
• End
24
Flowchart (Contd)
Practice Examples
The program asks the user for
a
positive number
25
Thanks
• 1. Fundamentals of Programming Languages
• 2. General Structure of C Programming Language/Python
26
Practice Question
• What is python? • What is interactive mode? • Why companies prefer python?
• Who Developed python? • What is the extension of python program/script? • List any 5 companies using python
• In which year the python came into existence? • What is the shortcut key to execute or run the script? • What are the advantages of python
• Where does the Python name come from? • What is anaconda navigator? • What are the disadvantages of python
• What is Python Shell or Python Interactive Shell? • What is Jupyter Notebook? • What is Cross platform language?
• What is interpreter? • Which function is used to quit python shell? • Write a note on history of Python
• How editor is different from IDE? • What is the function key to run/execute a python program? • What are the benefits of IDEs?
• List any four editors • What is the Differentiate between compiler and interpreter? • Explain any two popular Python IDEs?
• What is shell?
27
Chapter 2 – Python Programming
200IE-3 Data Inputs& Manipulation
200-IE-2 Data Inputs & Manipulation-Syllabus
Course Title Data Inputs& Manipulation
• Contents Course Code 200-IE-2
• 1. Fundamentals of No. of Units (Theoretical + Tutorial/Lab)
Level/ Year 4/2
Programming
Languages. General Structure
Prerequisite (if any)
of C Programming
Language/Python Course Assessment Python Companies
I. Quiz 15%
• 2. File I/O. String Processing, Variables
II. Assignment 15%
and Operations,
Sequences. If Basic I/O Functions,
Switch III. Mid Exams 20%
Statement, Statement, Loops, IV. Final Exam 40%
Functions. Loops, Nested V. Lab./Tutorial 10%
• 3. HTML, CSS, Web Scraping, Writing Teaching Methods
HTML and Basic Interfacing with SQL I. Lectures
Databases (Reading/Writing Data in II. Group Discussion
III. Study Assignments
Pre-existing Tables) IV. Interacting through E-learning
• 4. Software for Commercial V.
VI.
Lab. Experiments / Tutorial
Project & Trend Study
HTML: Hypertext Markup Language
• https://www.jetbrains.com/pycharm/download/#section=
windows
31
https://www.w3schools.com/
Language Features
• Python uses
• Indentation instead of Braces
• Several Sequence Types
• Strings: “…………” or made of
Characters.
‘……….’
• IMMUTABLE
• Lists: […..] made of anything
• MUTABLE
• Tuples: (……) made of anything
• IMMUTABLE
• Powerful Subscripting
• Functions are independent Entities –
not
32
all functions are methods
Programming Language - Python
• Python Programming Language
• Python is an interpreted, high-level, object-oriented, and general-purpose
programming language with dynamic semantics. Its design philosophy emphasizes
code readability with the use of significant indentation. It was originally released in
1991. It was designed and developed by Guido van Rossum.
• NOTE
• Case Sensitive – ‘A’ and ‘a’ are different; print and Print are NOT same.
• Interpreted
• Interactive
• Object Oriented
• Sequential Execution
• # Single Line Comment
• ‘’’ & ‘’’ Multiple Line Comment
• White Spaces – Python Ignores (BUT - Be Careful with Indentation)
• >>> Python Command Prompt/Python Shell
• print (‘ ’,) OR print (“ ”,)
• Indentation (hit ENTER) – Use TAB Key if needed
• \n New Line Character
33
Python uses dynamic semantics, meaning that its variables are dynamic
Run
Programming Cycle with some
input
Write/
Python
Edit OK?
NO
YES
NO
YES
More Inputs?
34
My First Python Program: Hello World
#Python Program using New Line Character “\n”
print ("Hello:\n","Welcome \n","to:\n","Python:\
n","Programming:\n") print ("Hello:\n Welcome: \n to:\n
Python:\n Programming:\n")
• Python Program Communicates its Results to User using print (‘…’) or print (“…”)
• Programs may need information from users, e.g.,
• Student Name, Student ID, DoB, Course Code, Course Name, Section, Year/Level, etc. in a University
Course Registration System
• ‘Python3’ uses command input to read user input as a string str 36
# Assign the values for length and width
length = 5
width = 10
# Calculate the area of the rectangle
area = length * width
# Print the result
print("The area of the rectangle is:", area, "square units")
Python Command: input
• The Python takes
arguments as string to
print it as a prompt يأخذPython الوسائط
كسلسلة لطباعتها كموجه يؤدي هذا إلى إرجاع
القيمة التي كتبها المستخدم كسلسلةThis
returns the user typed value as a string
38
Elements of Python
42
Thanks
• What is Python?
• Advantages & Disadvantages
• Simple Program
• Syntax
• Python Shell (Command Prompt)
• Python Shell Interpreter
• Python File Extension .py
• How to Run a Python File: F5
• Comments (Single & Multiple Lines)
• White Spaces
• Operators
• Inputs
• Variable
• type
• type Conversion
• How to see
• Output 42
Data
Types
Numeric
String
List
Tuple
Set
Dictio
nary
Ordered: It does not mean sorted. To sort the data, use sort
46
\n is a single Character: the special character representing
Python Strings: str (Contd)
48
Python Strings: str (Contd)
• Indexing A B C D E
• Strings can be indexed 0 1 2 3 4
• First character has index 0
• Negative Indexing -5 -4 -3 -2 -1
• Negative indices start counting from the right
• Negatives indices start from -1
• -1 means last, -2 second last, ...
• Too Large Indexing
• Using an index that is too large or too small results in “index out of
range” error
• Out of range indices are ignored for slicing when start and end
have the same sign, if start >=end, empty slice is returned
• Slicing String
• String slicing is about obtaining a sub-string from the given string
by slicing it respectively from start to end.
49
#String Slicing:
my_str = 'Welcome to the
52
Lists: lst
#Empty List #METHOD-2
#Initializing EMPTY my_list2=lis
Lists #METHOD-1 t()
my_list1=[ ] print(my_list
print 2)
(my_list1) #OUTPUT:
• List: lst #OUTPUT: [ ] []
• Lists are same as arrays. The arrays can have data type of only ONE type, e.g,
int, float, etc.
• Lists can have Heterogeneous Data Types.
• Lists are Mutable, i.e, we can change any items in the list.
• Example: a=[1, 'English', 3.142, 10+6j]
• Lists are written as a sequence with comma-separated values in a square
brackets. List is a sequence type and Sequence operations are applicable to it. List Sequence Type
• lst Operations
#Additing Elements into a List
• l.append(x)
• l.extend(seq) my_list1 =
• l.insert(i, x) [1,2,3,'pycharm','python'] my_list2
• l.remove(x) = list([4,5,3.142, 'Abha','Riyad'])
• l.pop(i) print (my_list1)
• l.pop() print
• l.index(x)
• l.count(x) (my_list2)
• l.sort() #OUTPUT
• l.reverse() #[1, 2, 3,
• Here, 'pycharm',
• x is any value 'python']
• seq is a sequence value (list,
#[4,string,
5,tuple, …) 53
• i is an integer value
3.142, Caution: Tuples and List types look very similar
Lists: lst (Contd)
• Practice Program
#Additing Elements into a List
my_list1 =
[1,2,3,'pycharm','python'] my_list2
= list([4,5,3.142, 'Abha','Riyad'])
print (my_list1)
print (my_list2)
#OUTPUT
#[1, 2, 3, 'pycharm', 'python']
#[4, 5, 3.142, 'Abha', 'Riyad']
my_list1 =
[1,2,3,'pycharm','python']
print(my_list1) #Accessing all
elements at a time (access whole
list without using index)
print(my_list1[:]) #Accessing all
54
elements at a time
Sequences (Includes - String, Tuple, List)
• Sequence
• Strings, Lists, and Tuples are examples of sequence. In these, the Lists are mutable, Tuple and Strings immutable.
• Indexing, slicing, concatenation, repetition operations applicable on sequences
• Sequence Unpacking
• Sequence Unpacking operation can be applied to sequences to get the components
• Multiple assignment statement
• LHS and RHS must have equal length
Operation Meaning
seq [i] ith element of the sequence
len (seq) Length of the sequence
seq1 + seq2 Concatenate the two sequences
num*se
Repeat seq num times
q
seq*nu
m
seq [start : end] slice starting from start, and ending at end
e in seq True if e is present is seq, False otherwise
55
e not in seq True if e is not present is seq, False otherwise
#Creating a Set
60
Data Type: set (Contd)
#Adding Elements (only one argument/element at a time) to
a Set
my_set1={1,2,3}
my_set1.add(4)
print(my_set1)
#OUTPUT: {1, 2, 3,
#Empty/Clear the 4}
Set my_set1.add(5)
my_set={1,2,3,4} print(my_set1)
#Other Methods in Sets: Union, Intersection, Difference, Symmetric
print(my_set) #OUTPUT:
Difference
{1, 2, 3, 4,
#OUTPUT: {1, 2, 3, 5}
#Union: all elements
4} #Intersection: Common
my_set.clear() Elements
print(my_set) #Difference: Delete common
#Difference Example #OUTPUT: elements
my_set={1,2,3,4} set() #Symmetric Difference: No-Common
my_set1={3,4,5,6} Elements. Remaining elements in
print(my_set.difference(my_s both the lists
et1)) #OUTPUT: {1, 2} #Union Example
print(my_set.difference(my_set1), '...', my_set - my_set={1,2,3,4}
my_set1) #OUTPUT: {1, 2} ... {1, 2} my_set1={3,4,5,6}
print(my_set.union(my_se
#Symmetric Difference t1)) #OUTPUT:Example
#Intersection {1, 2, 3, 4,
Example my_set={1,2,3,4} 5, 6}
my_set={1,2,3,4}
my_set1={3,4,5,6} print(my_set.union(my_se
my_set1={3,4,5,6}
print(my_set.symmetric_difference(my_ t1), '...', my_set |
print(my_set.intersection(my_s
set1)) #OUTPUT: {1, 2, 5, 6} my_set1)
et1)) #OUTPUT: {3, 4}
print(my_set.symmetric_difference(my_set1), #OUTPUT: {1, 2, 3, 4, 5,
print(my_set.intersection(my_set1), '...', my_set &
'...', my_set ^ my_set1) 6} ... {1, 2, 3, 4, 5, 6}
my_set1) #OUTPUT: {3, 4} ... {3, 4}
#OUTPUT: {1, 2, 5, 6} ... {1, 2, 5, 6}
61
#Initialize an Empty
Dictionary my_dict1={ }
Dictionary Construction
The dict constructor builds dictionaries directly from sequences of
key-value pairs
65
Thanks
66
Operator
s
Arithmetic
Comparison
Assignment
Logical
Bitwise
Membership
Identity
Python Operators
• In Python, Operators (Total 7) are special symbols that designate that some sort of computation to
be performed.
• The values that an operator acts on are called operands.
#Arithmetic Operator
a=10
b=5
print('Addition:', a+b) print('Subtraction:', a-b) print('Multiplication:', a*b) print('Division:', a/b)
print('Remainder:', a%b) print('Exponential:', a**b) #OUTPUT: Addition: 15
#OUTPUT:Subtraction: 5
#OUTPUT:Multiplication: 50
#OUTPUT:Division: 2.0
#OUTPUT:Remainder: 0
#OUTPUT:Exponential: 100000
63
Operators & Operations: Arithmetic Operators
Practice Q: Write Python Program and verify these Operations using Arithmetic Operat6o4
#Program: #Comparison Operators
while loop
for loop
Conditional Statements
• There are multiple ways to solve a problem with issues related to
• Readability
• Maintainability
if (very hot):
• efficiency and print ("I will skip exercise")
• decision making else:
• In our daily routine, we make decisions based on some constraints (conditions) print ("I will do
exercise")
• CASE1: If it is very hot, I will skip exercise.
• CASE2: If there is a quiz tomorrow, I will first study and then sleep. Otherwise, I will sleep now.
• CASE3: If I want to have coffee, I will go left. Else I will go straight.
if (quiz):
print (" I will first study and then
sleep ") else:
print (" I will sleep now ")
70
# Conditional Statements: if else
if-else Statement statements '''
#Questio
n1
x=int
• Question1: Compare two integer numbers and print the MINIMUM. (10)
• Question2: Compare two integer numbers and print the MAXIMUM. y=int(2
0) if x
< y:
#Find the Minimum (Small) #Find the Minimum (Small) pri
Number Number nt
x=10 x=10 (“X
y=20 y=20 is
#Questio
if x < y: if x > y: n2 Mi
x=int
print ("X is Minimum print ("X is MAXIMUM (10) ni
(Small):", x) else: (Large):", x) else: y=int(2mu
print ("Y is Minimum print ("Y is MAXIMUM 0) ifm”x
(Small)", y) (Large)", y) > y: , x)
else: pri
pri
nt
nt
(“X
#Questio
n3
#Take (“Y
is inputs from
User Mais
Mi
xi
x=int(input('Enter
ni
x:')) mu
mu
m”
y=int(input('Enter
,m”x)
Y:')) #x=10
else:
#y=20 , y)
''' pri
if (x>y):
nt
print('x is 71
Indentation
• Indentation refers to the spaces at the beginning of a
statement.
• Python uses indentation to indicate a block of code (grouping of
statements).
• There is no So, explicit
in Pythonuseindentation
brackets, e.g.is {very}, toimportant.
group statements in
Python.
• NOTE: In other programming languages the indentation is used for code readability only.
78
if & if-else statements
#Example1:
x=10
y=20
if (x<y):
• Execution of if statement (without else) print('x is
SMALL’) OUTPUT: x
• STEP1: if statement/expression is evaluated is SMALL
Thanks
print (‘You are
Welcome’) else:
print (‘You are NOT
Welcome’)
#Output: You are
• Q1: What is the value of expression: (5<2) and (3/0 > 1) Welcome
• (a) Run Time Crash / Error
• (b) I Don’t Know / I Don’t Care
• (c) False
• (d) True
• ANSWER: False
82
Python: Short-Circuit Evaluation/Lazy Evaluation
• Python's logical operators, logical and and logical or, are called as short-
circuit evaluation, or lazy evaluation.
• In other words, Python evaluates the operand on the right as and when it
is needed.
• The evaluation of expression takes place from left to right. #Example1
a=
• EX: first evaluate not((2>5) and (3/0>1)), then or(4/0<2) 1
b=
• NOTE: Do not evaluate the second operand of binary short-circuit logical operator if the result 2
can be deduced from the first operand. This is also applying to nested logical operators. c=
0
if
a>
#OUTPUT: At least one condition is
false
b
an
d
b>
c:
p
r
83
i
Evaluation of Expression
• Operators’ Order (Operators Precedence)
• Python Expression:
• Python Expression evaluates expressions from left to right.
• Python Assignment
• Right-Hand-Side is evaluated before the Left-Hand-Side.
• Precedence and associativity identify the operands for
each operator to evaluate first. #EX2: Operator Precedence of 'or' &
• Operators’ Precedence 'and' name = "Alex"
age = 0
• Applied to operators of different class if name == "Alex" or name == "John" and
age >= 20 : print("Hello! I Welcome You")
• + and *, - and *, else :
• logical and and logical or print("OOPs!! Good Bye!!")
#OUTPUT: Hello! I Welcome
You
80
while Loop
• A while loop will run a piece of code while a condition is True.
• It will keep executing the desired set of statements until the condition is no
longer True.
• A while loop will always first check the condition before running.
• If the condition evaluates to True, then the loop will run the code within the
loop's body.
• Flow Chart while Loop
• STEP1: Evaluate Expression/Condition
• STEP2: If Condition True then execute inside the while loop
• Go back to STEP2 and do it again and again until the condition is False
#while
• STEP3: If Condition False then End while loop. loop1
x=0
while
x<5:
print(x
)
#while
x=x+
loop2
x=1
1
while
x<5:
print(x
)
#while
x=x+
loop3
x=5
1
while
x<20: 81
print(x)
while Loop (contd): Examples
#Table of 2 using while
loop
i=1
while i<=10:
print("2x",str(i), "=",
i*2) i +=1
90
for Loop
• The for loop is used to iterate over a
sequence, which could be a list, tuple, array, or
string.
• The program operates as follows:
• We have assigned a variable x which is going to be a
placeholder for every item in our iterable object.
91
for Loop (contd): Examples
92
Practice Questions
• Question1: Find the output of the following python program.
# print all odd numbers < 10
i = 1
while i <= 10:
print(i)
if i%2==0: #
even #NOTE
continue i=1
print (i, end=' ') while i <=
i = i+1 10:
#Here, i is not incremented when even number print(i)
encountered. Infinite loop!! #Make sure continue does not bypass i += i
• Question2: Write a Python program to find Even numbers from 1 to 10
update-expression for while loops if i
%2==
using while loop. i=1 0:
while i <= continu
• Question3: Write a Python program to find Odd numbers from 1 to 10 10: i += ei
using while loop. if i//2 ==0:
%2 ==0:
#if i
continue
• Question4: Print the sum of the reciprocals of the first 100 print ('EVEN ', i)
numbers.
natural rsum=0.0# the reciprocal sum
# the for loop
for i in range(1,101):
rsum = rsum + 1.0/i
print ('sum is', rsum) 85
Thanks
for loop
86
Function
s
Built-in-function
97
function (Contd)
#Functions in Python
#Addition to ADD Two Numbers
def add (a, b): #function name addition
result = a+b
print ("RESULT",
result) add (5,10)
98
#ADDITION & MULTIPLICATION FUNCTION
functions: Examples
Reuasbility #
function
definition
(Contd) def
## Function return get_square(num)
Volume of Shapes: 3d Shapes : return num *
Type #function num
definition for i in [1,2,3]:
#OUTPU
def square(num): T
##Square
functionof 1
call
result = num * result= =1get_square(i)
#Square of 2 of',i,
print('Square
num return =4
'=',result)
result #Python Library Function #Square of 3
=9
# function call #Benefits of Using Functions
#1. Code Reusable - We can use the same function multiple
# Output:=The
SQUARE times in our program which makes our code reusable.
Square: 25
square(5) #2. Code Readability - Functions help us break our code into
# function that adds two
print('The chunks to make our program readable and easy to
numbers def understand.
Square:',SQUARE) import math
add_numbers(num1, num2): # sqrt computes the square root
sum = num1 + square_root = math.sqrt(4)
print("Square Root of 4
num2 return sum is",square_root) # pow() comptes
# calling function with two the power
power = pow(2, 3)
values result = print("2 to the power 3 is",power)
# Output:
add_numbers(5, 4) #OUTPUT:
#2 to the power 3 91
function Example: (Contd)
#Finding
Square def
square (a):
return a*a
for a in range (0,
10): print
(square(a))
#Finding
Square def
square (a):
return a*a
for a in range (0,
10):
print (square(a))
92
function (Contd): Examples
Area of Shapes: 2d Shapes
• Question1: Write a
program that calculates
the squares of numbers
ranging from 1 to 11
using a user-defined
function.
program can
that the
multiply
numbers in a list using
all
an inbuilt function.
93
Thanks
• functions
94
File
I/O
open
close
read
write
File I/O or File Handling
File I/O: Example
106
File I/O: Examples
107
Thanks
108
Practice Examples: Python Program
• Program 1: Get a list of numbers as input from a user and calculate the sum of it
• Functions to be used are:
• Use an input() function to accept the list elements from a user in the format of a string separated by space.
• Next, Use a split() function to split a string by space and added those numbers to the list.
• Next, iterate a user list using for loop and range() function.
• Convert each list element to an integer and add it to a sum variable.
• Program code:
input_string = input("Enter a list numbers or elements separated by space:
") userList = input_string.split()
print("user list is ", userList)
print("Calculating sum of element of input list")
sum = 0
for num in userList:
sum += int(num)
print("Sum = ", sum)
109
Python Program (Contd)
• Program 2: Write a programme to find a square root
of:
• (a) Given number
• (b) User defined number using Exponent, and
function
(math.sqrt(), math.pow()) Method
number = int(input("enter a number:
")) sqrt = number ** 0.5
print("square root:", sqrt) 2
import math
number = int(input("enter a number:"))
sqrt = math.sqrt(number)
print("square root:" , # Program to find Square root of given number
sqrt) import math import math # import the math module
number = int(input("enter a number:")) print(math.sqrt(0)) # print the square root of 0
sqrt = math.pow(number, 0.5) print(math.sqrt(4)) # print the square root of 4
print("square root: ", sqrt) print(math.sqrt(3.5)) # print the square root of 3.5
110
Python Program (Contd)
• Program 3: Write a programme to find a square of:
• (a) Given number
• (b) User defined number using Exponent, and function
(math.pow()) Method
• Calculating square is a basic operation in mathematics; here we are calculating the square of a given
number by using 3 methods.
• 1. By multiplying numbers two times: (number*number)
• 2. By using Exponent Operator (**): (number**2)
• 3. By using math.pow() method: (math.pow(number,2)
111
Python Program (Contd)
Program 3 (Contd)
# Python program to calculate square of a number
# Method 1 (using number*number)
# input a number
number = int (raw_input ("Enter an integer number: "))
square = number*number # calculate square
print "Square of {0} is {1} ".format (number, square)#
113
Python Program (Contd)
• Program 5: Write a programme to find the state (Positive, Negative
or Zero) of a given number and Entered number
114
Python Program (Contd)
1. # Program to multiply two matrices using nested
loops
2.
• Program 5: Write a program for 3. # 3x3 matrix
4. X = [[12,7,3],
Matrix multiplication using Nested 5. [4 ,5,6],
6. [7 ,8,9]]
Loop 7. # 3x4 matrix
8. Y = [[5,8,1,2],
9. [6,7,3,0],
10. [4,5,9,1]]
11. # result is 3x4
12. result = [[0,0,0,0],
13. [0,0,0,0],
14. [0,0,0,0]]
15.
16. # iterate through rows of X
17. for i in range(len(X)):
18. # iterate through columns of Y
19. for j in range(len(Y[0])):
20. # iterate through rows of Y
21. for k in range(len(Y)):
22.result[i][j] += X[i][k] *
Y[k][j] 23.
106
25. print(r)
24. for r in result:
Python Program (Contd)
• Program 6: Write a program for Matrix multiplication using
List Comprehension
1. # Program to multiply two matrices using list comprehension
2. # 3x3 matrix
3. X = [[12,7,3],
4. [4 ,5,6],
5. [7 ,8,9]]
6. # 3x4 matrix
7. Y = [[5,8,1,2],
8. [6,7,3,0],
9. [4,5,9,1]]
10. # result is 3x4
11. result = [[sum(a*b for a,b in zip(X_row,Y_col)) for Y_col in zip(*Y)] for X_row
in X]
12. for r in result:
13. print(r)
116
Thanks
• F1: Help
• Ctrl+S: Save
117
Chapter 3 – HTML
200IE-3 Data Inputs& Manipulation
200-IE-2 Data Inputs & Manipulation-Syllabus
Course Title Data Inputs& Manipulation
• Contents Course Code 200-IE-2
• 1. Fundamentals of No. of Units (Theoretical + Tutorial/Lab)
Level/ Year
3(2+1)
4/2
Programming
Languages. General Structure
Prerequisite (if any)
of C Programming
Language/Python Course Assessment Python Companies
I. Quiz 15%
• 2. File I/O. String Processing, Variables
II. Assignment 15%
and
Sequences.Operations,
If Basic I/O Switch
III. Mid Exams 20%
Functions, Statement,
Statement, Loops, IV. Final Exam 40%
Functions. Loops, Nested V. Lab./Tutorial 10%
• 3. HTML, CSS, Web Scraping, Writing Teaching Methods
HTML and Basic Interfacing with SQL I. Lectures
Databases (Reading/Writing Data in II. Group Discussion
III. Study Assignments
Pre-existing Tables) IV. Interacting through E-learning
• 4. Software for Commercial V.
VI.
Lab. Experiments / Tutorial
Project & Trend Study
HTML: Hypertext Markup Language
120
Introduction of HTML
• HTML is a language used for describing web pages.
• HTML stands for Hyper Text Markup Language
• HTML is not a programming language, it is a markup
language
• A markup language is a set of markup tags
• HTML uses markup tags to describe web pages
121
Introduction to HTML
• Introduction to HTML
• HTML (Hypertext Markup Language) is used to create document on the World Wide Web (www). It is simply a collection of certain key words called
‘Tags’. These Tags are used in writing the document to be displayed using a browser on the Internet.
• HTML is platform independent, i.e., it can be used on any platform such as Windows, Linux, Mac, etc.
• To display a document in web, it is essential to mark-up the different elements (headings, paragraphs, tables, etc.) of the document with the HTML
tags.
• To view a mark-up document, a user open the document in a web browser. A web browser understands and interpret the HTML tags, identifies the
structure of the document (which part are what) and makes decision about presentation (how the parts look) of the document.
• HTML also provides tags to make the document look attractive using graphics, font size and colors. User can make a link to the other document or
the different section of the same document by creating Hyper Text Links also known as Hyperlinks
• Objective of HTML
• create, save and view a HTML document
• format a web page using section heading tags
• describe Ordered and Unordered lists
• explain graphics in HTML document
• describe hypertext links and make text/image link
• World Wide Web (www)
• The World Wide Web (abbreviated as WWW or W3 and commonly known as the Web) is a system of interlinked hypertext documents accessed via
the Internet.
• With a web browser, one can view web pages that may contain text, images, videos, and other multimedia and navigate between them
HTML Tools
• There are two tools of HTML
• 1. HTML Editor
• It is the program that one uses to create and save HTML
documents. They fall into two categories:
• Notepad: It is a text based, or code-based editor which allows to
see and create HTML code.
• Netscape Composer: It is a HTML editor.
• 2. Web Browser
• It is the program that one uses to view and test the HTML
documents. The web browser translates the HTML encoded
files into text, image, sounds and other features that user
can see.
• Examples:
• Microsoft Internet Explorer, Microsoft Edge,
Netscape,
Mosaic, Google Chrome, Mozila, etc.
https://www.w3schools.co 114
HTML Terminology
• 1. Tag:
• Tags are always written within angle brackets. It is a piece of text that is used to identify an
element. This tells the browser how to display its contents.
• Example: <HTML> tag indicates the start of an HTML document & </HTML> tag indicates the end of an
document.
HTML
• HTML tag can be two types:
• Paired Tags:
• A tag is said to be a paired tag if text is placed between a tag and its companion's tag.
• Here, the first tag is referred to as opening tag and the second tag is referred to as
closing tag.
• Unpaired Tags:
• An unpaired tag does not have a companion tag.
• Unpaired tag is also known as singular or Stand-Alone tags, e.g., <br>, <hr> etc.
• 2. Attribute:
• Attribute is the property of a tag that is specified in the opening angle brackets.
• It supplies additional information like color, size, home font-style etc. to the browser about a
tag.
• Most of the common attributes are height, color, width, src, border, align, etc.
• 3. Document Type Definition (DTD)
• It is a collection of rules written in Standard Generalized Markup Language (SGML).
• HTML is defined in terms of its DTDS.
• All the details of HTML tags, entities and related document structure are defined in the DTDS.
• 4. Element
• Element is the component of a document’s structure such as a title, a paragraph or a list.
• Element can include an opening and a closing tag and the contents within it.
115
How to Create HTML Document?
120
Text Tags & Character Formatting Tag (Contd)
• Common Character Formatting Tags
• Boldface <B>: Displays text in BOLD
• Example: Welcome to the <B> Internet World </B>
• Output: Welcome to the Internet World
• Italics <I>: Displays text in Italic
• Example: Welcome to the <I> Internet
World </I>
• Output: Welcome to the Internet World
• Subscript <SUB>: Displays text
in Subscript
• Superscript <SUP>: Displays
text in Superscript
• Small <SMALL>: Displays text in smaller font as compared to
normal font
• Big <BIG>: Displays text in larger font as compared to normal
• Example:<U> hello</u>
font
• Output: hello 121
Font Colors and Size:<FONT>
• By using <FONT> Tag one can specify the color, size of the text.
• Example: <FONT> Your text goes here </FONT>
• Attributes of <FONT> are:
• COLOR: Sets the color of the text that will appear on the screen.
• It can be set by giving the value as #rr0000 for red (in RGB hexadecimal format), or by name.
• Example: <FONT COLOR="RED"> Your text goes here </FONT>
• SIZE: Sets the size of the text, takes value between 1 and 7, default is 3.
• Size can also be set relative to default size.
• Example: SIZE=X, where X is any integer value, and it will add with the default size.
• Example: <FONT SIZE=5> Font Size changes to 5 </FONT>
• FACE: Sets the normal font type, provided it is installed on the user’s machine.
• Example1: <FONT FACE=“ARIAL”> the text will be displayed in Arial</FONT>
• Example2: <FONT FACE=“Broadway"> the text will be displayed in Arial</FONT>
• Example3: <FONT FACE=“Jumble"> the text will be displayed in Arial</FONT>
131
HTML Document format: Example
• An HTML Document format text.html shows the use of
Character Formatting Tags
<HTML>
<HEAD>
<TITLE>
Use of Character Formatting Text Tags Output
</TITLE>
</HEAD>
<BODY>
<H1><I> Welcome to the world of
Internet</I></H1> It is a
<FONT COLOR="BLUE" SIZE="4">
<U>Network of Networks</U>
</FONT>
</BODY>
</HTML>
132
Marquee Tag
135
Using Preformatted Text Tag: <PRE>
• <PRE> tag can be used, where it requires total control over spacing and line breaks such as
typing a poem.
• Browser preserves your space and line break in the text written inside the tag.
• Example:
<PRE>
Data Inputs & Manipulations
200-IE-4, Level 2/4
Section 126/1283, Year 2022
</PRE>
• Output:
Data Inputs & Manipulations
200-IE-4, Level 2/4
Section
126/1283, Year
2022 136
HTML document: use of <P>, <BR> and <PRE>
• An HTML document control.html shows the use of <P>, <BR> and <PRE>
<HTML>
<HEAD>
<TITLE> PRACTICE QUESTION: Write the Output of
Use of Paragraph, Line break and preformatted text Tag the Following HTML Code
</TITLE> <HTML>
</HEAD> </P>
<P>
<BODY> HTML stands for Hypertext
1. HTML Learning - HTML stands for Hypertext Markup Markup Language.<BR>
It is used for creating web
Language It is used for creating web page. It is very simple page. It is very
and easy to learn. 2. HTML Learning - HTML stands for simple.<BR>
and easy to learn.<BR>
Hypertext Markup Language </P>
It is used for creating web page. It is very simple and <PRE>
HTML stands for Hypertext
easy to learn. Markup Language
<P> It is used for creating web page. It is very
simple and easy to learn.
HTML stands for Hypertext Markup Language </PRE>
It is used for creating web page. It is very simple and </BODY>
</HTML>
easy to learn.
137
Horizontal Rule Tag: <HR>
• Horizontal Rule Tag: <HR>
• An empty tag <HR> basically used to draw lines and horizontal rules. It can be used to
Example:
separate two sections of text. Example:
<BODY>
• <HR> accepts following Attributes
Your horizontal rule goes here.
• SIZE: Determines the thickness of the horizontal rule. The value is given as a pixel value. <HR> The rest of the text goes
Example: <HR SIZE="3">
here.
• WIDTH: Specifies an exact width of <HR> in pixels, or a relative width as percentage
</BODY>
OUTPUT:
of the
document width.
Your horizontal rule goes
Example: <HR WIDTH="50%">, horizontal rule a width a 50 percent of the page width.
• ALIGN: Set the alignment of the rule to LEFT, RIGHT and CENTER. It is applicable if it is not here. The rest of the text
equal to width of the page. goes here
Takeaway QUESTION: Draw a Vertical
• NOSHADE: If a solid bar is required, this attribute is used; it specifies that the horizontal rule line
should not be shaded at all. HTML.
• COLOR: Set the color of the Horizontal rule.
Example: <HR COLOR="BLUE“>
Example of <HR> with its attribute:
<HR ALIGN=' 'CENTER' ' WIDTH=' '50%' ' SIZE=' '3" NOSHADE
COLOR="BLUE“>
129
Heading: <H1>.............<H6> Tags
• Header Tags
• HTML has SIX HEADER tags <H1>, <H2>...........<H6> used to specify
section headings.
• Text with header tags is displayed in larger and bolder fonts than the
normal body text by a web browser.
• Every header leaves a blank line above and below it when displayed
in browse.
• Example: An HTML document, headings.html shows the different
section headings
<HTML>
<HEAD>
<TITLE>
Section Heading
</TITLE>
Viewing Output of HTML Document headings.html in Browser
</HEAD>
<BODY>
<H1> This is Section Heading 1 This is Section
</H1>
<H2> This is Section
</H2>
Heading 2 Heading 1
<H3> This is Section
</H3>
Heading 3 This is Section Heading 2
<H4> This is Section Heading 4 This is Section
</H4>
<H5> This is Section Heading 5
Heading
This is Section3 This is 130
Special Characters in HTML
• There are certain special characters that can be used while
creating document. Following are some special character:
• Symbols Entity
Example: Special Characters in HTML
©, ® ©, ® <PRE>
The copyright symbol is:
¼, ½, ¾ ¼, ½, ¾ ©
÷, <, >, ≤,≥ ÷, <, >, &le, &ge The registered rank is: ®
</PRE>
& & Output:
♣♠♥ &spades, &clubs, &hearts The copyright symbol is:©
The registered rank is:®
Caution: All these special character must be ended with a
semicolon ; 131
Practice HTML
<!============>
<!Comment>
<HTML> <!============>
<!Comment 1>
<HEAD>
<HTML>
<TITLE> <HEAD>
Web <TITLE>
</TITLE> KKU
</TITLE>
</HEAD> </HEAD>
<BODY> <BODY>
<b> Hello World </b> <b><i><u> Course: 200IE-3 Data Input &
Manipulation
<br>
</u></i></b> <br>
<u> HTML & CSS</u> <b>Chapter2: Python Programming</b><br>
<br> <i> Chapter3: HTML & CSS</i><br>
HELLO<sup>2</sup> <b> <h1>Chapter4: MySQL</b></h1>
</BODY>
<br> HI<sub>2</sub> </HTML>
</BODY> <! <!Comment 2> 137
==========
Practice HTML (Contd) <!============>
<!Comment: .gif
Image============>
<html>
<BODY BGCOLOR=“Light
Green"> Your document text
goes here.
</BODY>
<BODY TEXT="Red"> Introduction to
HTML! In this the Document text
changed to red color!
</BODY>
<BODY
BACKGROUND="chickenGIF.gif">
Document text changed to red color
</html>
<!============>
138
Reference URL: https://ww
Advantages & Disadvantages of HTML
• HTML, CSS, JS
• HTML provides the basic structure of sites, which is enhanced and modified by other
technologies like CSS and JavaScript (JS).
• CSS is used to control presentation, formatting, color, and layout.
• JavaScript is used to control the behavior of different elements.
148
Thanks
149
Chapter 4 – CSS
200IE-3 Data Inputs& Manipulation
Introduction to CSS
• Overview
• What is CSS?
• Why to use CSS?
• CSS for Skinning for Website
• Structure
• CSS Syntax
• Three places CSS can be defined
• CSS Syntax
• Cascading Inheritance
• Applied
• CSS Hands-on
https://www.w3schools.co
m/ 142
Cascading Style Sheet (CSS)
• Cascading Style Sheet (CSS)
• CSS is a Stylesheet Language. CSS stands for Cascading Style Sheets.
• CSS describes how HTML elements are to be displayed on screen, paper, or in other media and saves
a lot of work, time, and efforts.
• CSS has a standard set of properties and attributes to define styles
• CSS describe the presentation of a document written in a ‘markup language’ like HTML or XML
• Markup encoding: <p> My paragraph here. </p>
• Defines the style of how things in <p> tags appear.
• font, color, size, margins, etc.
• Cascading
• Rules to determine how to apply markup that contains other markup
<div> tag defines a division or a section in an HTML document
XML (Extensible Markup Language) is a markup language similar to HTML, but without predefined tags to use. Instead, user define his/her own tags designed
specifically
for their needs. This is a powerful way to store data in a format that can be stored, 143
searched, and shared.
Cascading Style Sheet (CSS): Why CSS?
<font size=“14px”> Old
• Separate Content Form My First Header way
• Content: </font>
from <font size=“12px” color=“red”
• It is the text and images.
• It is marked up to define regions of specific types.
face=“Arial”> My information 1 goes
here.
• Form:
</font>
• It defines the “style” for the content
<font
• Separate Content from Form (Old vs. New) size=“14px”>
• Specify the style once for every instance of that My Second
Header
class.
</font>
• Example:
<font
• Specify the font once for all text on the HTML page <p class=“header”>My First Header</p>
size=“12px” Content
<p class=“info”>My Information 1 goes here</p>
that the user has identified as a “header”. color=“red”
<p class=“header”>My Second Header</p>
• The stylesheet can be separate file which all face=“Arial”>
<p class=“info”>Different Information goes here</p>
• Specify the style, only once for your ENITRE SITE information goes
.header
here. { font-size:14px;} Form or Style
• It can change the style of the entire site by editing .info { font-family: verdana;
</font>font-color: blue;
only ONE FILE font-size: 12px; }
144
CSS Skinning
• “Skinning”
• This changes the look of a page in the site by selecting an appearance by choosing
which stylesheet to be used.
EXAMPLE1 EXAMPLE2
<link rel="stylesheet" type="text/css" href=“skin1.css" /> <link rel="stylesheet" type="text/css" href=“skin2.css" />
<p class=“info”>Hello Data Inputs & Manipulation</p> <p class=“info”>My Information 1 goes here</p>
+ +
skin1.css skin1.css
.info { background-color: White; .info { background-color: Blue;
font-family: Verdana; font-family: Serif;
font-color: Blue; } font-color: White; }
= =
Hello Data Inputs & Manipulation Hello Data Inputs & Manipulation
154
CSS Syntax
• Elements to CSS Statements: Three
• Selector
• What HTML sections does it affect?
• Property
• What attribute of that HTML section will be affected?
• Value
• What change will be made to that attribute?
• Selectors
• There are many kinds of selectors available in CSS
with many ways to reference them:
• Type, Class, ID, Pseudo, etc.
• HTML Type Tag – selected with the tag type
p{ font-size: 10px;
font-color: White; }
.myinfo { font-size: 10px;
font-color: White; }
<p>Content</p>
<p class=“myinfo”>Content</p>
• The Class Attribute – precede the class with a period <div class=“myinfo”>Other content</div>
155
CSS Definition Locations: Three
• Inline: the “style”
attribute <p style=“font-color:red;font-size:10px;”>Content</p>
<html><head><style>
• Internal: the <style> markup tag p{ background-color: Red;
font-family: serif;
font-color: White; }
</style></head><body>
<p>Content</p>
</body></html>
156
Cascading Inheritance
• Nested elements inherit the properties from the
its parent
• If you specify a style for the <body> tag it body { font-family: Verdana;
font-size: 14px; }
will affect all content in your HTML page.
158
HTML vs CSS (Contd)
• Webpage in CSS
159
HTML vs CSS (Contd)
160
Thanks
• html interfacing with SQL Database
• For this you need to follow the following steps:
• Step 1: Filter your HTML form requirements for your contact us
web page.
• Step 2: Create a database and a table in MySQL.
• Step 3: Create HTML form for connecting to database.
• Step 4: Create a PHP page to save data from HTML form to
your MySQL database.
• Step 5: All done!
161
Project Idea (Webpage): HTML & CSS
• Basic Layout of Website
162
Project Idea (Webpage): HTML & CSS
• Source Code
<!DOCTYPE html>
<html>
<head>
<title>WebLayout</title>
</head>
<body>
<div style="border: 1px solid black; width: 98.7%; height: 80px;"></div>
<div style="border: 1px solid black; width: 20%; height: 500px; float: left;"></div>
<div style="border: 1px solid black; width: 78.5%; height: 500px; float: left;">
<div style="border: 1px solid black; width: 90%; height: 80px; margin-top: 20px; margin-left:
5%;"></div>
<div style="border: 1px solid black; width: 40%; height: 350px; margin-top: 10px; margin-left: 5%;
float: left;"></div>
<div style="border: 1px solid black; width: 40%; height: 350px; margin-top: 10px; margin-left:
55%;"></div>
154
</div>
Chapter 5 - MySQL
200IE-3 Data Inputs & Manipulation
200-IE-2 Data Inputs & Manipulation-Syllabus
Course Title Data Inputs& Manipulation
• Contents Course Code 200-IE-2
• 1. Fundamentals of No. of Units (Theoretical + Tutorial/Lab)
Level/ Year 4/2
Programming
Languages. General Structure
Prerequisite (if any)
of C Programming
Language/Python Course Assessment Python Companies
I. Quiz 15%
• 2. File I/O. String Processing, Variables
II. Assignment 15%
and
Sequences.Operations,
If Basic I/O Switch
III. Mid Exams 20%
Functions, Statement,
Statement, Loops, IV. Final Exam 40%
Functions. Loops, Nested V. Lab./Tutorial 10%
• 3. HTML, CSS, Web Scraping, Writing Teaching Methods
HTML and Basic Interfacing with SQL I. Lectures
Databases (Reading/Writing Data in II. Group Discussion
III. Study Assignments
Pre-existing Tables) IV. Interacting through E-learning
• 4. Software for Commercial V.
VI.
Lab. Experiments / Tutorial
Project & Trend Study
HTML: Hypertext Markup Language
Objectives on
Structured Query Language
(SQL).
SQL and MySQL are database-
• Introduction to MySQL languages.
related
While SQL is a programming language
• Connecting and Disconnecting used
• Entering Basic Queries to workis with
MySQL data in relational
an open- database
• databases,
that
product source
implements the SQL
Creating and using a Database
standard.
157
DBMS
• MySQL is a Relational Database Management System
(RDBMS) developed by ORACLE Corporation that is based
on Structured Query Language (SQL).
• Database: A database is an or structured
organized
• Ex: Student
collection of information or data.a DBMS
Attendance Systems Table of Relational Database
• Data Operations: Create, Read, Update, Delete
• Queries: Store, Retrieve, run query on data
• NOTE: Storing Raw Data & Extracting some Information from
the Data:
• Ex: from Student Data, extracting who has register for the
course on “Data Inputs and Manipulation”
• Relational Database Management System (RDBMS): A
Relational Database is a collection of data items with pre-
defined relationships between them, stored in the form
of table, rows and columns.
• Types/List of SQL Databases
• MySQL
• MariaDB
• Oracle
• PostgreSQL
• MSSQL 158
Introduction to MySQL
• SQL (Structured Query Language):
• SQL is the standard language for dealing with Relational Databases. SQL is used to
insert, search, update, and delete database records. SQL is primarily used to query
and operate database systems. SQL does not support any connector.
• MySQL
• MySQL allows you to handle, store, modify and delete data and store data in an
organized way.
• MySQL comes with an in-built tool known as MySQL Workbench that facilitates
creating, designing, and building databases.
• MySQL is a very popular, Open-Source Database.
• MySQL is officially pronounced as “My Ess Que Ell” (not my sequel).
• MySQL handles very large databases
• MySQL has very fast performance.
• Why are we using MySQL?
• Free and much cheaper than Oracle
• Easy to use with Java JDBC (Database Connectivity)
• Each student can install MySQL locally
• Easy to use Shell for creating tables, querying tables, etc.
168
Installing MySQL
Custom Installation
169
Getting Started: Connecting to MySQL
• Connecting to MySQL
• MySQL provides an interactive shell for creating tables, inserting
• On
data, etc.
Windows, just go to
• C:\Users\neera\cd C:\Program Files\MySQL\MySQL Server 8.0\bin
• C:\Program Files\MySQL\MySQL Server 8.0\bin>mysql –u root –p
• Enter password: ****** NOTE: 123456
• mysql>
• OR
• click on the Windows icon
• Click on the MySQL Shell
• Sample Session
• For Example:
E
n or \g.
t
e
r
p
a
s
s
mysql>show databases; This will show the myname database in the list of database
w
o
r
• To exit the MySQL
d
Shell, just type QUIT or EXIT:
mysql> QUIT
:
mysql> exit 161
*
Some of the most Important SQL
Basic Queries Commands
•SELECT
•UPDATE
- extracts data from a database
- updates data in a database
•DELETE - deletes data from a database
• MySQL Query is any command that used to retrieve •INSERT INTO - inserts new data into a database
•CREATE DATABASE - creates a new database
the data from a table. •ALTER DATABASE - modifies a database
•CREATE TABLE - creates a new table
• MySQL can be used for querying the data, •ALTER TABLE - modifies a table
filtering data, sorting data, joining the tables, •DROP TABLE - deletes a table
•CREATE INDEX - creates an index (search key)
grouping data, modifying the data. •DROP INDEX - deletes an index
• Once Logged-In, try some simple MySQL queries.
• For Example:
mysql> SELECT VERSION();
+ +
| VERSION() |
+ +
| 5.01.35 |
+ +
1 row in set (0.00 sec)
172
Basic Queries (Contd)
• You can also enter multiple statements on a single line by ending each
one with a semicolon ;
multiple
mysql> SELECT VERSION(), NOW(); statements
+ +
|+version() | |
+
now() + +
| | 2023-02-03
8.0.32 +23:12:24 |
+ +
Owner VARCHAR(20)
Species VARCHAR(20)
176
Describing & Deleting Tables
• Describing Table
• To view a table structure, use the DESCRIBE command:
mysql> describe pet;
+ + + + + +
+
| Field | Type | Null | Key | Default | Extra
|
+ + + + + +
+
| name | varchar(20) | YES | | NULL |
|
| owner | varchar(20) | YES | | NULL |
|
| species | varchar(20) | YES | | NULL |
|
| gender | char(1) | YES | | NULL |
|
| birth | date | YES | | NULL |
|
| death | date | YES | | NULL |
|
+ + + + + +
+
6 rows in set (0.02 sec)
169
SQL Query: A simple SQL query would begin with a select statement, followed by
SQL Select the field names you want to display and the selection criteria.
mysql> select name from pet where death >IS NOT NULL;
Working with NULLs: + +
• NULL means Missing Value or Unknown Value. | name |
• To test for NULL, don’t use the arithmetic comparison operators, such as +--------+
=, < or <>.IS IS NOT operator | Bowser |
• Use theNULL and
NULL +--------+
s. 1 row in set (0.01 sec)
• Example: To find all your dead pets! 172
To find names beginning with ‘b’:
mysql> SELECT * FROM pet WHERE name LIKE "b%";
Pattern Matching
+ + + + + + +
| name | owner | species | sex | birth | death |
+ + + + + + +
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
| Bowser | Diane | dog | m | 1989-08-31 | 1995-07-29 |
• MySQL provides: +--------+--------+---------+------+------------+------------+
• standard SQL pattern matching; and regular expression To find names ending with `fy':
pattern matching, like those used by Unix utilities such as
mysql> SELECT * FROM pet WHERE name LIKE "%fy";
vi, grep and sed. +--------+--------+---------+------+------------+-------+
• SQL Pattern matching: | name | owner | species | sex | birth | death |
• To perform pattern matching, use the LIKE or NOT LIKE +--------+--------+---------+------+------------+-------+
comparison operators | Fluffy | Harold | cat | f | 1993-02-04 | NULL |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
• By default, patterns are case insensitive (not case sensitive). +--------+--------+---------+------+------------+-------+
• Special Characters:
• _ Used to match any single character. To find names containing a ‘w’:
• % Used to match an arbitrary number of characters. mysql> SELECT * FROM pet WHERE name LIKE "%w%";
• Examples: +----------+-------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
• To find names beginning with ‘b’: + + + + + + +
• To find names ending with `fy’: | Claws | Gwen | cat | m | 1994-03-17 | NULL |
• To find names containing a ‘w’: | Bowser | Diane | dog | m | 1989-08-31 | 1995-07-29 |
| Whistler | Gwen | bird | NULL | 1997-12-09 | NULL |
• To find names containing exactly five characters, use + + + + + + +
the _ pattern character:
To find names containing exactly five characters, use the _ pattern character:
mysql> SELECT * FROM pet WHERE name LIKE “ ";
+ + + + + + +
| name | owner | species | sex | birth | death |
+ + + + + + +
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Buffy | Harold | dog | f | 1989-05-13173| NULL |
+ + + + + + +
Regular Expression (RE) Matching
• The other type of pattern matching provided by MySQL uses extended regular expressions.
• When you test for a match for this type of pattern, use the REGEXP and NOT REGEXP operators
(or RLIKE and NOT RLIKE).
• Reg Ex Example:
• To find names beginning with b, use ^ to match the beginning of the name:
mysql> SELECT * FROM pet WHERE name REGEXP
+
"^b"; + + + + + +
| name | owner | species | sex | birth | death |
+ + + + + + +
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
| Bowser | Diane | dog | m | 1989-08-31 | 1995-07-29 |
+ + + + + + +
• To find names ending with `fy', use `$' to match the end of the name:
176
MySQL Shell Commands
MySQL Shell provides commands which enable you to modify the execution
environment of the code editor, for example to configure the active
programming language or a MySQL Server connection. As commands need to
be available independent of the execution mode, they start with an escape
sequence, the \ character.
Command Alias/Shortcut Description
\help \h or \? Print help about MySQL Shell or search the online help.
\quit \q or \exit Exit MySQL Shell.
\ In SQL mode, begin multiple-line mode. Code is cached and executed when an empty line is
entered.
\status \s Show the current MySQL Shell status.
\js Switch execution mode to JavaScript.
\py Switch execution mode to Python.
\sql Switch execution mode to SQL.
\connect \c Connect to a MySQL instance.
\reconnect Reconnect to the same MySQL instance.
\disconnect Disconnect the global session.
\use \u Specify the schema to use.
\source \. or source Execute a script file using the active language.
\warnings \W Show any warnings generated by a statement.
\nowarnings \w Do not show any warnings generated by a statement.
\history View and edit command line history.
\rehash Manually update the autocomplete name cache.
\option Query and change MySQL Shell configuration options.
\show Run the specified report using the provided options and arguments.
\watch Run the specified report using the provided options and arguments and refresh the results at
regular intervals.
\edit \e Open a command in the default system editor then present it in MySQL Shell.
\pager \P Configure the pager which MySQL Shell uses to display text.
Practice Questions
179
Chapter 6 – Commercial Software &
Applications
200IE-3 Data Inputs& Manipulation
200-IE-2 Data Inputs & Manipulation-Syllabus
Course Title Data Inputs& Manipulation
• Contents Course Code 200-IE-2
• 1. Fundamentals of No. of Units (Theoretical + Tutorial/Lab)
Level/ Year
3(2+1)
4/2
Programming
Languages. General Structure
Prerequisite (if any)
of C Programming
Language/Python Course Assessment Python Companies
I. Quiz 15%
• 2. File I/O. String Processing, Variables
II. Assignment 15%
and
Sequences.Operations,
If Basic I/O Switch
III. Mid Exams 20%
Functions, Statement,
Statement, Loops, IV. Final Exam 40%
Functions. Loops, Nested V. Lab./Tutorial 10%
• 3. HTML, CSS, Web Scraping, Writing Teaching Methods
HTML and Basic Interfacing with SQL I. Lectures
Databases (Reading/Writing Data II. Group Discussion
III. Study Assignments
in Pre-existing Tables) IV. Interacting through E-learning
• 4. Software for V.
VI.
Lab. Experiments / Tutorial
Project & Trend Study
HTML: Hypertext Markup Language
Ref:
1. https://www.techopedia.com/definition/4245/commercial-software 185
2. https://www.geeksforgeeks.org/difference-between-open-source-software-and-commercial-software/#:~:text=Some%20examples%20of%20commercial%20software,SAP%2C%20Oracle%2C%20A
Small Projects
200IE-3 Data Inputs& Manipulation
Small Projects (Ideas)
• Python
• HTML
• HTML & CSS
• HTML & CSS & JS
• MySQL
196
Survey Form in HTML
197
Survey Form in HTML (Contd) <header><strong>Please Check that
Apply</strong></header>
<DOCTYPE html> <div></div>
<html> <br>
<head> <label>I Love Shopping</label>
<title>Survey Form in <input type="checkbox"></input>
HTML</title> <div></div>
</head> <br>
<div id="outside"> <label>I Work Full Time</label>
<body bgcolor="lightblue"> <input type="checkbox"></input>
<!form action="youtube.com" method="POST" style="text- <div></div>
align:center"> <br>
<h1 style="text-align:center;">Survey Form</h1> <label>I Love to Play Football<label>
<p style="text-align:center"><strong>Note</strong>: Fill the Survey <input type="checkbox"></input>
Form on/before <div></div>
<strong>07 Days</strong> </p> <br>
<hr> <label>I Earn more the $5000 per
<br> Month</label>
<div></div> <input type="checkbox"></input>
<header><strong>Personal Details</strong></header> <div></div>
<br> <h3>This Information is Correct<h3>
<label>First Name</label> <div></div>
<input type="text" placeholder="Enter Your First Name"></input> <br>
<div></div> <hr>
<br> <br>
<label>Last Name<label> <header>REMARKS<header>
<input type="text" placeholder="Enter Your Last Name"></input> <p>Your Hobbies in about 20 Words</p>
<div></div> <label>Hobbies</label>
<br> <textarea type="text"
<label>Current Age</label> name="message"></textarea>
<div></
<input type="number" value="30"></input> div>
<div></div> <!-- Rate -->
<br> <div class="form-control">
<label>Gender<label> <div class="heading-field">
<select option="Gender" name="Gender"></option> <h3 class="field-head">Ratings </h3>
<option value="Male" name="Male">Male</option> </div>
<option value="Female" name="Female">Female</option> <div class="field-inputs">
</select> <h5>Rating 1:</h5>
<br> <div class="input-div">
<div></div> <input type="radio" id="bad" name="rating1"
<br> value="bad">
<label>Email Address<label> <label for="bad">Bad</label><br>
<input type="email" placeholder="Please Enter Your <input type="radio" id="good" name="rating1"
Email"></input> value="good">
<div></div> <label for="good">Good</label><br>
<br> <input type="radio" id="Excellent" name="rating1"
<label>Phone Number<label> value="excellent">
<div></
<input type="text" placeholder="Your Phone div> <label for="excellent">Excellent</label><br>
<br
Number"></input> ><button
<div></div> type="Submit">Submit</button>
<br> <br>
<label>IQ Level</label> </ 189
<input
<br type="number" placeholder="IQ LEVEL"></input> </body>
<div></div>
> html>
Import .xls & .csv files to MySQL
Workbench
199
Import .xls & .csv files to MySQL Workbench
• .csv file:
• A CSV (Comma-Separated Values) file is a text file that has a specific format which
allows data to be saved in a table structured format.
• .xls/.xlxs file:
• The XLSX and XLS file extensions are used for Microsoft Excel spreadsheets, part
of the Microsoft Office Suite of software. XLSX/XLS files are used to store and
manage data such as numbers, formulas, text, and drawing shapes.
• Difference in .csv & .xls files:
• The difference between CSV and XLS file formats is that CSV format is a plain text
format in which values are separated by commas (Comma Separated Values),
while XLS file format is an Excel Sheets binary file format which holds information
about all the worksheets in a file, including both content and formatting.
200
Thanks
• All the Best
• Python – High Level Programming
Language
• HTML
• CSS
• MySQL Server, Workbench, Shell
• Small Project
201
#Q6 Example6: Develop a flowchart to find the AREA of a Rectangle. Also, write
Practice Questions
the Python Program.
#Q6 Example6 Develop a flowchart to Calculate the Area of a
Rectangle. l=int(input("Enter Length:"))
w=int(input("Enter
Width:")) area = l*w
print ("Area = ", area)
202
Online Compiler
• print(type("hello"))
• print(type(2+8j))
• print(type(2.20))
203