0% found this document useful (0 votes)
28 views203 pages

Programming & Data Manipulation

The document outlines the syllabus for a course on Data Inputs and Manipulation, covering programming fundamentals, file I/O, web technologies, and SQL. It details course objectives, assessment methods, and required software installations, while also comparing programming languages like C and Python. Additionally, it discusses the importance of data manipulation, the role of MySQL, and the basics of HTML and CSS.

Uploaded by

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

Programming & Data Manipulation

The document outlines the syllabus for a course on Data Inputs and Manipulation, covering programming fundamentals, file I/O, web technologies, and SQL. It details course objectives, assessment methods, and required software installations, while also comparing programming languages like C and Python. Additionally, it discusses the importance of data manipulation, the role of MySQL, and the basics of HTML and CSS.

Uploaded by

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

Data Inputs & 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

Application, Small Projects CSS: Cascading Style Sheets


NOTE: any change shall be updated
SQL: Structured Query Lan3guage
Objectives
• Python
• To understand how to download and install an open-source software, e.g., Python IDE.
• To define the structure and components of a Python program.
• To learn how to write loops and decision statements in Python.
• To learn how to write functions and pass arguments in Python.
• HTML & CSS
• To understand and learn HTML Tags.
• To understand how a web page is structured, organized, and presented in a web-browser.
• To learn how to use HTML (the language of the web) to create a range of web pages and for
developing web applications.
• To become familiar with a personal computer, Web Browsers, windows Operating System, and
the Internet.
• MySQL
• To learn and understand how to download and install MySQL Server, Workbench, and Shell.
• To understand and learn MySQL Queries.
• To learn how to use MySQL Workbench and MySQL Shell.
• To learn how to retrieve and manipulate data from one or more tables.
• Learn how to filter data based upon multiple conditions.
• Update and insert data into the existing tables.
4
Text & Reference Books
• Textbook
• Programming in Python 3: A Complete Introduction to the Python Language by Mark Summerfield,
Pearson Education Publisher, 2nd Edition, 2018.
• Reference Book
• Python in a Nutshell, 3e: A Desktop Quick Reference by Alex Martelli, Anna Ravenscroft, and Steve
Holden, 3rd Edition, O′Reilly Publisher 2017.
• Fluent Python: Clear, Concise, and Effective Programming by Luciano Ramalho, O′Reilly Publisher, 1st
Edition, 2015
• Web
• www.python.org
• https://www.jetbrains.com/pycharm/
• https://html.com/
• https://www.mysql.com/
• https://www.w3schools.com/
• Software Installation
• Python
• PyCharm IDE
• MySQL: Server, Workbench, Shell

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

Don’t repeat the same mistake and expect


Programming Language - C
• C Programming Language
• C language is a system programming language because it can be
used to do low-level programming (for example driver and kernel).
• It is generally used to create hardware devices, OS, drivers, kernels,
etc.
• For example: Linux kernel is written in C.
• It can't be used for internet programming like Java, .Net, PHP, etc.

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

Procedural Oriented Language Object Oriented Language

Structured Programming Language Interpreted Programming Language

High Speed Slow Speed

Less Library Functions Rich Library

Easy to Extend Easy to Learn

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

#Flow Chart: To find a Number Greater the


Other
a=int(input("Enter A:"))
b=int(input("Enter
B:")) if a > b:
print("A is
LARGEST")
else:
print ("B is
LARGEST")

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 Script mode? • What is Spyder?


• What is Python distribution?
• Write down the steps to invoke python software
• What is Jupyter Notebook? • What is PyScripter?
• What are the basic modes of python?
• What is translator? • Is python supports object-oriented programming?
• Write down the steps to run/execute a program or
• What is compiler? • What is the shortcut key to exit from python shell? script

• What is interpreter? • Which function is used to quit python shell? • Write a note on history of Python

• What is an IDE? • What is quit() function?


• Draw and explain the screen elements of Python

• • What is multi paradigm programming language?


What is Python IDE or IDLE? • What is exit() function?
• Is Python multi paradigm programming language
• What is an editor? • What is Debug? justify your answer

• 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

Application, Small Projects CSS: Cascading Style Sheets


NOTE: any change shall be updated
SQL: Structured Query La2n9guage
Objectives
• Overview
• History
• Why Python?
• Python Software
• Download
• Installation
• Language Features
• Basic Syntax
• Data Types
• Operators
• Flow Control
• Functions
• File Handling
• Python (Laboratory Practice): ONLINE COMPILER
1. https://www.programiz.com/python-programming/online-compiler/
2. https://www.online-python.com/
3. https://onecompiler.com/python
4. www.w3schools.com 30
Python IDE Installation
• https://www.python.org/downloads/

• 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")

• 1. Python: Interactive Shell >>>


The Python interactive console (also called the Python
interpreter or Python shell) provides programmers
with a quick way to execute commands and try out or
test code without creating a file. ‫وفر وحدة التحكم‬
‫ التفاعلية في‬Python (‫ والتي تسمى أيًضا ُمفّس ر‬Python
‫ أو غالف‬Python) ‫للمبرمجين طريقة سريعة لتنفيذ األوامر‬
‫وتجربة أو اختبار التعليمات البرمجية دون إنشاء ملف‬.

• 2. Python File: hello.py


The Python script is basically a file containing code
written in Python. The file containing python script has
the extension . py

Programming Syntax Semantics


Language (Python)

It refers to the rules of It refers to the


Syntax & Semantics any statement in the meaning associated with
programming language. any statement in the 35
programming
Python Shell – “Interactive Python Shell”
• >>> Python Shell Prompt
• >>> print (‘Hello World’) User Command/Statement
• Hello World Output
• >>> 10 + 20 User Command/Statement
• 30 Output
• >>> 5 > 10 User Command/Statement
• False Output
• >>> print (‘5+10 is:’ 5+10) User Command/Statement
• 5+10 is: 15 Output
• >>> abs(-15) User Command/Statement (Absolute
• >>> 15 Value)
Output
• >>> Python Shell Prompt

• 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

• A Python program is a sequence of definitions and


commands (statements)
• Commands manipulate objects (value)
• Each object (value) is associated with a type
• type:
• Scalar
• int (signed integer): Bounded Integers: 151, 25, -14,
-3, etc.
• float (floating point): Real Numbers: 5.0, 2.51,
3.142, etc.
• long: Long Integers with Unlimited Precision
• bool: Boolean (True/False)
• none: This is a special type with a single value. The
value is called as none
• Non-Scalar:
• str (string): String: “Welcome”, ‘Hello World’, ‘P’, etc.
• Expressions:
• An operation (combination of objects and operators)
39
Elements of Python
(Contd): Example

• type Commands - Practice


• >>> type(151)
• >>> type(-151)
• >>> type(0.151)
• >>> type(15.1) Python is case sensitive
Be careful in Typing: TRUE /
• >>> type(True) TRYE
• >>> type(False)
• >>> type(TRUE)
• >>> type(FALSE)
• >>> type(‘TRUE’)
• >>> type(‘FALSE’)
• >>> type(“TRUE”)
• >>> type(“FALSE”)
• >>> type(“TRUE & FALSE”)
• >>> type(‘TRUE & FALSE’)
• >>> type(“151 & 15.1 & True”)
• >>> type(‘151 & 15.1 & True’)
39
type (contd)
• type Conversion
• Conversion of value of one
type to other type
• Ex: int ↔ float
• Integer 5 is treated as float
5.0
• NOTE: Float 3.6 is truncated
as 3 or rounded off as 4 for
integer contexts.
• Python type float int
conversion
to is
truncation, not rounding off
• Command type
• >>> int (5.0)
• >>> float (5)
41
type Conversion & input
• Single Line Comment #
• Multiple Line Comment ‘’’ Line1…. Line2…. Line3.… ‘’’
• age = input ('What is Your age?')
• #print ('After 10 Years, Yoyr Age will be ...', age+10)
• print ('After 10 Years, Yoyr Age will be ...', int(age)+10)

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

Data Types in Python


command.

• Categories of Python Data Types


• Mutable: Data can be changed after creation. Readable/Writable Data. So,
Slow Speed.
• List : Mixed Type of Data
• Sets : Mixed Type of Data
• Dictionary
• Immutable: Data can not be changed after creation. But the Data can be
deleted. Only, Readable Data. So, Fast Speed.
• Numeric (int, float, complex): Same Type of Data (numbers)
• String : Same Type of Data (characters)
• Tuples
String List Tuple Set Dictionary
Immutable Mutable Immutable Mutable Mutable
Ordered/Indexed Ordered/Indexed Ordered/Indexed Unsorted Unsorted
Allows duplicate members Allows duplicate members Allows duplicate members Doesn’t allow duplicate Doesn’t allow duplicate
members members
Empty string = “ ” Empty list = [ ] Empty tuple = ( ) Empty set = set { } Empty dictionary = { : }
String with a single List with a single item = Tuple with a single item = Set with a single item = Dictionary with single item =
element = “H” [“Hello”] (“Hello”) {“Hello”} my_set1={1,2,3} {“Hello”:1}
my_tuple1=(1,2,3,4,5) my_dict3={1:'Python',2:'MySQ
L'}
It can store data type string, It can store data type, str, It can store data type, str, It can store data type (int, Inside dictionary key can be
only list, tuple, numeric, and list, tuple, numeric, and str, tuple) but not int, str, and tuple only
#Numeric Data Types: int, float,
complex #int - Integer: 1, 5, 365, -

Python numeric Data Types 365


#float - Float: 3.1427
#complex - 5+7j
#Program1: Numeric Data Type
#Integer, Float,and Complex
• Python has three built-in numeric data types: Numbers a=10 #integer type
b=-10
• int: Integers c=3.142 #float type
d=.142
• float: Floating-point Numbers, and e=10+3j#complex
type f=6j
• a+bj: Complex Numbers print(a+b, c-d, e-f,
end='\n')
print(a-c, b-f, a*b,
#Program2: Simple Calculator
end='\n')
Model # Take Inputs from user
# Perform Addition,
Subtraction, … #....
Multiplication, and Division…
#Program3: Temperature Converter F # …Operation on TWO Integer
to oC Numbers
#Take Inputs from User a=int (input('Enter a: '))
f=int (input('Enter Temperature b=int (input('Enter b:
in F: ')) c=(f-32)*(5/9) ')) print
print ("Temperature in 0C = ", c) ('------------------------')
#Program4: Temperature Converter #Program5: Area Calculation of a print ('Addition: ',
oC to F #Take Inputs from User Circle #Take Inputs from User: (a+b)) print
c=int (input('Enter Temperature in Radius r = 10 r=int (input('Enter ('------------------------')
0C: ')) f=(c*(9/5))+32 Radius in Meters: ‘)) area=3.14*r*r print ('Subtraction: ',
45
print ("Temperature in 0C = ", f) print (“Area of Circle in Meter2 = ", (a-b))
print
#EX1: Creating a string
Python Strings: str my_str = 'Welcome to the
python' print(my_str)
#OUTPUT: Welcome to the
python
• String
• Strings are a collection of characters. They represent sequence of
#Ex2: Creating a string
characters. Strings in Python have type str my_str1 = "This is my
• Strings are enclosed in single quotes (‘ ‘) or double quotes (“ ”). string" print(my_str1)
Both are equivalent. #OUTPUT:This is my
• Strings are NOT Mutable (Immutable) string
• Example: string = 'welcome to python'
• Length of String Function len

46
\n is a single Character: the special character representing
Python Strings: str (Contd)

• Concatenate and Repeat


• In Python, + and *
have special meaning when
operations
operating on strings
• + is used for
concatenation the
strings of
• * is used to repeat(two)a string
upto an int number of time

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

Slicing String python' print(my_str[:]) #Print


all #OUTPUT: Welcome to the
python
print(my_str[2:10]) #Print from Index 2 until index 9
• Slicing and skip 10lcome
#OUTPUT:
to
• To obtain a substring from a given string print(my_str[0:14:1]) #Print from Index 0 until 13 skipping
• s[start:end] means substring of s starting at 1 element Welcome to
#OUTPUT:
index start and ending at index end-1 the
print(my_str[0:14:2]) #Print from Index 0 until 13 skipping
• Both start and end are optional. 2 element Wloet
#OUTPUT:
• If start is omitted, it defaults to 0 h
#Other Functions
• If end is omitted, it defaults to the length of
my_str = 'Welcome to the
string
python'
print(len(my_str)) #Return Length (including
• Understanding Indices for slicing space)
#OUTPUT:
21
A B C D E print(my_str.count('t')) #return length of the string. 't'
repeated 3 times.
0 1 2 3 4 #OUTPUT: 3

-5 -4 -3 -2 -1 print(my_str.lower()) #convert to lower case


#OUTPUT: welcome to the python

print(my_str.upper()) #convert to upper case


#OUTPUT: WELCOME TO THE 49
PYTHON
Tuples
• Tuples are used to store multiple items in a single variable.
#Empty Tuple
my_tuple1=() #empty tuple: It is used where we
exactly don't know what data is to be send into the
• Tuple data types are same as list with one exception that
tuple my_tuple2=tuple()
.‫ُتستخدم المجموعات لتخزين عناصر متعددة في متغير واحد‬
tuples print(my_tuple1)
‫أنواع بيانات المجموعات هي نفسها القائمة باستثناء واحد‬
are not mutable (immutable), i.e., the data in the tuple can not #OUTPUT:
be changed. This makes tuples much faster than lists. ()
print(my_tuple2)
• tuples are declared using parenthesis and tuples can have #OUTPUT:
Heterogeneous Data Types. ()
my_tuple1=my_tuple1+(1, 2, 3, 4, 5)
• Empty/Singleton tuple: It is used where we exactly don't know #Empty tuple: This is the way; the data is
what data is to be send into the tuple populated slowly. print(my_tuple1)
• Tuples can be nested: A Tuple can be copied into another Tuple #OUTPUT:
without affecting the Tuple. #()
• NOTE: A tuple with a single element should have a comma at #()
the end. Otherwise, it will be considered as String (str) #(1, 2, 3, 4, 5)
• Example1: my_tuple='welcome’, #This is string print(type(my_tuple1))
• Example2: a=(1, 'English', 3.142, 10+6j) #This is tuple #OUTPUT: <class
'tuple'>
my_tuple1=(1,2,3,4,5)
#initializing print(my_tuple1)
tuples #OUTPUT: (1, 2, 3, 4,
5)
my_tuple2=('abha','asir','jedda','r
my_tuple1=()
iyad') print(my_tuple2)
my_tuple2=tupl #OUTPUT: ('abha', 'asir', 'jedda',
e()
#OUTPUT: 'riyad')
()
print(my_tuple1 my_tuple3=(1,2,3,3.147,'abha','a
)#OUTPUT: Caution: Tuples and List types look very similar #OUTPUT: (1, 2, 3, 3.147, 'abha', 'asir', 'jedda',
sir','jedda','riyad')
my_str = 'Welcome to the python
Tuples (Contd)
#Accessing elements in the tuple: It is same as in #How to Change Data in aa
the lists my_tuple1=(1,2,3,4,5) Tuple #my_tuple4=(1,2,3,
my_tuple2=('abha','asir','jedda','riyad') ['python','mysql’])
#Here, ['python','mysql’]. #Since list is mutable, we can
my_tuple4=(1,2,3,['python','mysql’]) change this data. #So, wee change this list data
#Here, ['python','mysql']. Since list is mutable, we can
['python','mysql']
change this data.
#Let’s change mysql to CSS
print(my_tuple1[ my_tuple4=(1,2,3,
0]) ['python','mysql'])
print(my_tuple2[
#OUTPUT: my_tuple4[3][1]='CSS'
1])
1
#OUTPUT: print(my_tuple4)
print(my_tuple4[
asir
#OUTPUT: #OUTPUT: (1, 2, 3, ['python', 'CSS']) #The python is change to CSS
2]) in the list. #NOTE: Original tuple elements 1,2,3 can't be changed.
3print(my_tuple1
[:]) #tuple
#OUTPUT: methods: index and count
print(my_tuple2 0
functions my_tuple4=(1,2,3,
print(my_tuple4.count
[:])
#OUTPUT:(1, 2, 3, 4, ['python','mysql'])
(1))
#OUTPUT:
5) 1
print(my_tuple4.count(0))
print(my_tuple4.count
print(my_tuple4 'asir', 'jedda',
#OUTPUT:('abha',
(2))
#OUTPUT:
[:])
'riyad')
#OUTPUT:(1, 2, 3, ['python', 1
print(my_tuple4.count
'mysql'])
print(my_tuple2[3] (3))
#OUTPUT:
[1])
#OUTPUT: 1
print(my_tuple4.count
iprint(my_tuple4[3] (4))
#OUTPUT:
[1])
#OUTPUT: 0
print(my_tuple4.index(['python','m
ysql']))
#OUTPUT:3 #the index value of list element 51
mysql
['python','mysql']
Tuple (Contd): Length & More Operations

• len function gives the length of Length


a tuple‫ تعطي دالة‬len ‫طول‬
‫مجموعة من األرقام مزيد من العمليات على‬
‫المجموعات يمكن ربط المجموعات‬
‫وتكرارها وفهرستها وتقطيعها‬
• More Operations on Tuples
• Tuples can be concatenated,
repeated, indexed and sliced

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

Data Type: set


my_set={1,4,2,3,5,5,4,5,
5,5}
print(my_set)
#OUTPUT: {1, 2, 3, 4,
• set: Difference: It returns a set that contains the 5}
difference between two sets.
• Sets are an un-ordered collection of "unique elements The returned set contains items that exist only in the first set, and not in
(no duplicate entries)". Elements in a set are both sets.
repeated.not
Sets are written with comma, only. Sets are Union: It returns a set that contains all items from the original set, and all
mutable. items from the specified set(s).
• Example: a = {1,2,3,4,5} Intersection: It returns a set that contains the similarity between two or
• Set Supports more sets. The returned set contains only items that exist in both sets, or in
all sets if the comparison is done with more than two sets.
• membership testing Symmetric Difference: This method returns a set that contains all items
• eliminating duplicate entries from both set, but not the items that are present in both sets. Meaning:
• Set operations The returned set contains a mix of items that are not present in both sets.
• union, intersection, difference, and symmetric difference
• Create a set from a sequence Set
Operations
Caution: See difference with dictionary (key value
pair).

Create a set from a sequence

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={ }

Data Type: dictionaries


print(my_dict1)
# { } #This is empty
dictionary
my_dict2={
}
print(my_dict
• Dictionary Data Types #Initialize
2) # Elements
{} in a
• Dictionary data Types are used to hold key : value pairs Dictionary
• Dictionaries are Mutable (can be changed as lists). my_dict3={1:'Python',2:'MySQ
L'} print(my_dict3)
• Example: mydict={‘City':'Abha','State':'Asir’}
#OUTPUT: {1: 'Python', 2:
• Key - City 'MySQL'}
• Value – Abha my_dict4={1:'Abha',2:'
• Key – State Asir'} print(my_dict4)
• Value - Asir #Accessing Elements in a Dictionary
#OUTPUT: {1:using
'Abha',
• Unordered set of key:value pairs. Key my_dict4={1:'Abha',2:'Asir'}
2: 'Asir'} # get the
• Keys must be unique and immutable value by key print(my_dict4[2]) # get the
value by key #OUTPUT: Asir
• key:value pairs enclosed inside curly braces {...} my_dict5={'first':'python','second':'my
• Empty dictionary is created by writing { } sql'} print(my_dict5['first']) # get the
• Dictionaries are mutable. It can value by key #OUTPUT: python
• add new key:value pairs print(my_dict5['second']) # get the value
by key #OUTPUT: mysql
• change the pairing
#Uinsing .get function
• delete a key (and associated value) print(my_dict5.get('first')) # Using get
58
function
#OUTPUT: in the same way.
Data Type: dictionaries (Contd)
#Delete Elements (key value pair) from a # Change & Add Elements in the
Dictionary my_dict6={'first': 'python', 'second': Dictionary
'C++', 'third': 'JAVA'} print(my_dict6) my_dict5={'first':'python','second':'my
#OUTPUT: {'first': 'python', 'second': 'C++', sql'} print(my_dict5)
'third': 'JAVA'} a=my_dict6.pop('third') #OUTPUT: {'first': 'python', 'second': 'mysql'}
print(my_dict6) my_dict5['second']='C++' #This will change mysql
#OUTPUT: {'first': 'python', 'second': 'C++'} with C++ print(my_dict5)
my_dict6.clea #OUTPUT:{'first': 'python', 'second': 'C++'}
r() my_dict5['third']='JAVA' #Add a new 'THIRD' key
print(my_dict value pair print(my_dict5)
6) #OUTPUT:{'first': 'python', 'second': 'C++', 'third':
#OUTPUT: {} 'JAVA'}
#This clearFunctions
#Other the in Dictionary
dictionary and
my_dict6={'first':
make it an empty 'python', 'second': 'C++',
'third':
dictionary'JAVA'} print(my_dict6.keys())
#OUTPUT: dict_keys(['first', 'second', 'third'])
print(my_dict6.values())
#OUTPUT: dict_values(['python', 'C++', 'JAVA'])
print(my_dict6.items()) #This will return the key value pair in the
dictionary #OUTPUT: dict_items([('first', 'python'), ('second', 'C+
+'), ('third', 'JAVA')]) print(my_dict6.get('first'))
59
#OUTPUT: python
Directories: Operations
• Operations on Dictionaries

Dictionary Construction
The dict constructor builds dictionaries directly from sequences of
key-value pairs

65
Thanks

Caution: Tuples and List types look very similar

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

Operator Meaning Example Remarks


+ Addition 9+2 is 11 int
9.1+2.0 is 11.1 float
- Subtraction 9-2 is 7 int
9.1-2.0 is 7.1 float
* Multiplication 9*2 is 18 int
9.1*2.0 is 18.2 float
/ Division 9/2 is 4.25 In Python3
9.1/2.0 is 4.55 Real Division
// Integer Division 9//2 is 4 Quotient
% Remainder 9%2 is 1 Remainder

Practice Q: Write Python Program and verify these Operations using Arithmetic Operat6o4
#Program: #Comparison Operators

Operators (Contd) a=5


b=1
0
#Program: #Assignment Operator print(a==b)#True if equal
#OUTPUT: False print(a!
a=5 a=5 =b)#True if NOT equal
a +=1 a- #OUTPUT: True
a =1 print(a>b)#True if a is greater
6 a than b #OUTPUT: False
print(a<b)#True if a is less than
a += 2 4 b
print( a- #OUTPUT: True
a) 8 =2 print(a>=b)#True if a is greater than or
a+=3 a equal to b #OUTPUT: False
print(a<=b)#True if a is less than or
a 2 a=5 #Program:
equal to be#Logical
#OUTPUT:Operators
True
1 a-=a a**= a=5 #if argument is 1 or greater than 1, it
1 print( is True b=0 #if argument is 0, it is always
1a
False
a a) 0 5 print(a and b) # True if both are True
+ a**= #OUTPUT: 0
= 2a print(a or b) # True if either is
a True #OUTPUT: 5
25
print(not a) # returns the
a
opposite value
2 #OUTPUT: False 65
Variables
• Binding:
• Name binding is the association between
a name and an object (value).
• We bind (or attach) a name to an object.
• Use assignment operator (=) to bind a
name to an object.
• Variable
• A name is associated with an object.
• Assignment Operator (=) is used for
binding
• Ex:
• n=75;
• a=‘welcome’;
• p=3.14137;
• Variables can change their bindings
• p=2.113355;
66
Assignment Statement: using Assignment
Operator =
• Single Assignment Statements
• Assignment Statement (assignment operator = ): LHS = RHS
• Variable = Expression;
• Computes the object(value) of the expression on the Right-Hand Side (RHS)
• Associates the name (variable) on the Left-Hand Side (LHS) with the RHS value # Binding-
Ex2 x, y =
• Multiple Assignment Statements 15, 27
• Python allows multiple assignments. x, y = y-1,
x-1
OUTPUT: 26
• Ex: x, y = 15, 27 Binds: x is bound to 15 and y is bound to 27 14
print(x,y)
#Binding-Ex3
• Evaluation of multiple assignment statement: x, y = 5, 10
• All the expressions on the RHS of the assignment operator “ = “ are first evaluated x, y = x**2,
y*5
before any binding happens. print(x,y)
OUTPUT: 25
• Values of the expressions are bound to the corresponding variable on the LHS. 50
• Ex: x, y = 15, Binds: x is bound to 15 and y is bound to 27
27 x, y = y+1, Binds: x is bound to 28 and y to 16 at the end of the program
x+1
Practice Example1: Evaluate the x, y = 15, 27
expression: x, y = y-1, x-1 67
OUTPUT: 26 14
The Operator: // and %
• The Operator //
• The Operator // is also referred to as “Floor
Division/Integer
Division”
• This operator will divide the first argument by the second and round
the result down to the nearest whole number, making it equivalent to
the math. Here, the type need not be int
• Output: The Result is a whole integer.
• Example:
9//4 is 2
1//2 is 0
• Remainder Operator %
• The Remainder Operator % returns the remainder of the result,
i.e., the division of first operand by second operand.
• Example:
9%4 is 1
9%4.5 is 0.0 68
Control
Statemen
ts
if else
if & if else
nested if else
elif

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

• STEP2: If it is true, then Statement1 is #Example2:


x=2
executed. And control transferred/moves to 0
y=1
the Statement2 0
• STEP3: If its is false, then control moves to if
(x<
Statement2, and it is evaluated. y):
pr
• Execution of if-else Statement in
t('
• STEP1: if statement/expression is evaluated. x #Questio
is
• STEP2: If statement/expression is true, then S
n1
x=int
(10)
Statement1 is executed. And control M
A
y=int(2
0) if x
transferred/moves to Statement3. LL < y:
') pri
• STEP3: If statement/expression is false, then #O nt
UTP (x)
#OUTPUT:
Statement2 is executed. And control UT:
MINIMUM
else:
pri
transferred/moves to Statement3. ????
???? nt
79
(y)
???
print
Nested if, if else Statement
• Nested if else statements are used to execute different piece
of code when we have more than two options to handle.

#EXAMPLE: Nested if-else


Statement n=int(input('Enter a
Number: '))
if n>= 0:
if n==0:
print ('You have entered
ZERO')
else:
print('You have entered a
Positive Number')
else:
print ('You have entered a
Negative Number') 74
#Example: nested if #Example: if…elif…
else
elif Statements
if cond1: else
if cond1:
s1 s
else:
1 elif
if
cond2: cond2:
s
• A special kind of nesting is the chain of else:
s2
2 elif
if-else-if-else-… statements that if cond3:
cond3: s
be
canwritten elegantly using if-elif-..-else s 3
3 e
#Conditional Statement: else:
lif

#Simple if-else-elif …
Statement a=10 else
l
b=15
as
if a==b: t-
print('They are equal') bl
elif a>b: oc
print('a is k-
of
Larger') else: -
print ("b is st
Larger") b is
#OUTPUT: at 75
#Q: Find the Output of Python
program. y = 0.1*5
if y != 0.5:

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

#EX1: Operators Precedence of +


and * # Precedence of '+' & '*'
expr = 3 + 5 *
10 print(expr)
78
#OUTPUT: 53
Argument1 Multiplicat Argument2 Assignme Result
io n nt

Python: Multiplication Table 5 X 1


Operator
= 5
5 X 2 = 10
5 X 3 = 15
5 X 4 = 20
Multiplication Table in Python 5 X 5 = 25
# Printing Multiplication Table in Python 5 X 6 = 30
n = int(input('Enter a number: ')) 5 X 7 = 35
print (n, 'X', 1, '=', n*1) 5 X 8 = 40
print (n, 'X', 2, '=', n*2) 5 X 9 = 45
print (n, 'X', 3, '=', n*3) 5 X 10 = 50
print (n, 'X', 4, '=', n*4)
#OUTPUT:
print (n, 'X', 5, '=', n*5) Enter a
print (n, 'X', 6, '=', n*6) number: 5 5 X
1=5
print (n, 'X’, 7, '=', n*7) 5 X 2 = 10
print (n, 'X’, 8, '=', n*8) 5 X 3 = 15
print (n, 'X’, 9, '=', n*9) 5 X 4 = 20
5 X 5 = 25
print (n, 'X’, 10, '=', n*10) 5 X 6 = 30
5 X 7 = 35
The Situation: Too much repetition! Can I avoid this? 5 X 8 = 40
5 X 9 = 45
Possibility of Typing Error due to Copy & Paste 5 X = 5079
#Multiplication Table using while
Loop n = int(input('Enter a
Python: Multiplication Table (Contd) number:'))
i=1
while (i <= 10) :
print (n ,'X', i, '=', n*i)
i=i+1
print
(‘DONE')

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

User Defined Function


function
Parts of a function

• In computer programming, a function is a named section of a code


that performs a specific task.
• Functions are blocks of code which run whenever they are called.
Functions reduces redundancies and increase reusability. Python
supports "pass by object”.
• Function Types:
• 1. Built-in-function
• 2. User Defined Function
• Typically, a function involves in taking input, manipulating input,
and returning output.
• Create & Define Function:
• The def
keyword only creates and defines a function.
• Call Function:
• To call a function, use the function name, followed by
parentheses.

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 def add (a,b): #Define a function using def


keyword
print('Sum of A & B =',(a+b))
def mul (a,b): #Define a function using def
#Simple Function Examples keyword print('Mul of A & B =',(a*b))
#Example1: User Defined Function - add(5,10) #Parameters are passed in the
fun1() def fun1(): fnctions
#OUTPUT mul(5,10) #Parameters are passed
print('Hello World') :in the fnctions
#Sum of A & B =
fun1() # call the 15
#Mul of A & B =
function
#OUTPUT: ???? 50
? #Built-in / In-built
#Example2: User Defined Function - Functions list1=[1,0,7]
fun2() def fun2(): print(abs(-5)) #abs
print('Hello World-Welcome to Python "absolute". It returns
World') fun2() # call the function the positive value of
print('Function Already Completed') the passed
print('Now, You are Outside of the argument.
print(an (list1)) # returns if any element is True (1 value
Function Already’)
#OUTPUT: ???? y
print(all(list1))
or
print len list1) #returns if all elements are True. Since there is
higher)
? ( it) is False
(a 0, so
print(mi
#Python Function Arguments: a function can also have n
(list1))
print(max(list
arguments. #A arguments is a value that is accepted by a print(sum(list
1))
function. 1))
print(type(list
# function with two #OUTPU
1))
arguments def add(num1, T
#
num2): 5
#Fals
e Tru
#
sum = num1 +
e
#
num2 print('Sum:
#OUTPUT: Sum: 3
15',sum) #
add(5,10) #Calling 0
the function with #
#<class 90
TWO Arguments 7
'list'>
#Code

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.

• Question2: Write a Volume of Shapes: 3d Shapes

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

• File Handling or File I/O


• The basic operations on files are open, close, read, write
• Steps: 1. Open a file;
• 2. Perform Operations;
• 3. Close file
• You need to make sure that you close file to avoid damaging data in the file File handling is an integral part of
• Python provides methods to handle files where we can read and write data into it. File handling in Python is simplified with
programming. built-
in methods, which include creating, opening,
• • Modes:
File Read Mode, Write Mode, and Append Mode.
and
closing files.
• Files are persistent storage. Allow data to be stored beyond program lifetime
• sequence While files are open, Python additionally
• Python operations
treat files work for
as sequence ofthe data read from files
lines
allows performing various file operations,
• File I/O (contd): open and close such as reading (r), writing (w), and
• open(filename, mode) file_object=open('my_text','w') #w:
appending (a) information.
• While opening a file, you need to supply write mode for text in range (100):
• The name of the file, including the path file_object.write('Hello World! This is my
• The mode in which you want to open a file text.\n') file_object.close()
• Common modes are count=0
• r (read) file=open('my_text','r') #r:
• w (write) read mode for lines in file:
• a (append) count=count+1
• Mode is optional, defaults to r print(count, 'lines are
• open(..) returns a file object present') file.close()
• close() on the file object closes the file #OUTPUT: 100 lines are
• finishes any buffered operations present
#This will create a file with my_text name in the same location where this Python
file
#Openis written.
this my_text file. This file will have 100 line of "Hello World! This is
File I/O:

File I/O: read, write and append


Examples

• Reading from an open file


• returns the contents of the file as sequence of lines in the program
• Writing to a file
• IMPORTANT: If opened with mode 'w', clears the existing
contents of the file
• Use append mode ('a') to preserve the contents
• Writing happens at the end

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)#

# Python program to calculate square of a number

# Method 2 (using number**2)


# input a number
number = int (raw_input ("Enter an integer number: "))
square = number**2 # calculate square
print "Square of {0} is {1} ".format (number, square)

# Python program to calculate square of a number


# Method 3 (using math.pow () method)
import math # importing math library 2f are called as format specifiers, they begin with %
# input a number followed by character that represents the data type.
number = int (raw_input ("Enter an integer number: ")) For e.g
square = int(math.pow (number, 2)) # calculate square %d format specifier is a placeholder for a integer,
print "Square of {0} is {1} ".format (number, square) similarly
%. 2f is a placeholder for floating point number. 112
Python Program (Contd)
• Program 4: Write a programme to find an Area of a circle
and Circumference of a circle:
# Python Program to find Area of Circle and Circumference using Radius
PI = 3.14
radius = float(input(' Please Enter the radius of a circle:
')) area = PI * radius * radius
circumference = 2 * PI * radius
print(" Area Of a Circle = %.2f" %area)
print(" Circumference Of a Circle = %.2f"
%circumference)

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

Application, Small Projects CSS: Cascading Style Sheets


NOTE: any change shall be updated
SQL: Structured Query L1a1n0guage
html & CSS Contents
• HTML
• Introduction of HTML
• Objective of HTML
• World Wide Web (www)
• HTML Tools
• HTML Terminology
• How to Create an HTML Document
• Saving & Viewing HTML Document
• Text Tags
• Special Character
• Advantages of HTML
• Disadvantages of HTML
• CSS
• Overview
• Structure

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?

• The essential tags that are required to create a


HTML
document are:
• <HTML>.............</HTML>
• <HEAD>.............</HEAD>
• <BODY>.............</BODY>
• HTML
• TheTag <HTML>
<HTML> tag encloses all other HTML tags and associated text
within the document. It is an optional tag.
• NOTE: You can create an HTML document that omits these tags, and your
browser can still read it and display it. But it is always a good form to
include the start and stop tags.
• The format is: Your Title and Document (contains text with HTML
tags) goes here
• <HTML>
• </HTML>
• Most HTML tags have two parts, an opening tag and closing tag.
• The closing tag is the same as the opening tag, except for the slash mark,
e.g., </HTML>.
• The slash mark is always used in closing tags. 116
HTML Document: Two parts HEAD & BODY
• HEAD Tag <HEAD>
• HEAD tag comes after the HTML start tag. It contains TITLE tag to give the document a title that displays <HTML>
on the browsers title bar at the top.
• The Format is:

<HEAD>
<HEAD>
• <TITLE> .............
• Your title goes here
• </TITLE> .............
• </HEAD>
• BODY Tag <BODY> .............
• The BODY tag contains all the text and graphics of the document with all the HTML tags that are used for
control and formatting of the page.
</HEAD>
• The Format is:
• <BODY> <BODY>

• </BODY>
Your Document (text, image, etc.) goes here .............
• Creating HTML Document .............
• An HTML document or web page can be created using a Text Editor, Notepad or WordPad or Notepad++.
• All the HTML documents should have the extension .htm or html. .............
• It require a web browser like Internet Explorer, Google Chrome, Microsoft Edge,
Netscape Navigator/Communicator, etc. to view the document. </
BODY>
</HTML> 117
Attributes used with <BODY>
• BGCOLOR: It is used to set the background color for the
• Example:
document
• <BODY BGCOLOR="yellow">
Your document text goes here.
• </BODY>
• TEXT: It is used to set the text color of the document
• Example:
• <BODY TEXT="red"> Introduction to HTML:: 77
• Document text changed to red color
• </BODY>
• NOTE: Here, the Document text changed to red color
• MARGINS: It sets the left hand/right hand margin of the document LEFTMARGIN: set the left-hand margin of the document
• Example: <html>
• <BODY LEFTMARGIN="60"> <BODY BGCOLOR="Yellow">
• This document is indented 60 pixels from the left-hand side of the page. Your document text goes here.
• </BODY> </BODY>
<BODY TEXT="Red"> Introduction to HTML:: 77
• TOPMARGIN: It sets the top margin of the document Document text changed to red color
• Example: </BODY>
<BODY
• <BODY TOPMARGIN="60"> BACKGROUND="f5baef4b6b6677020ab8d091ef78a3bc.gif">
• This document is indented 60 pixels from the top of the page. <BODY BACKGROUND="KOXOBiN.gif">
Document text changed to red color
• </BODY> </html>
• BACKGROUND: It is used to point to an image file (the files with an extension .gif, .jpeg) that will be used as the background of the
document. The image file will be tiled across the document.
• Example:
• <BODY BACKGROUND="filename.gif">
• Your document text goes here
• </BODY> 118
<BODY
Follow the steps to create and view in browser
• Creating a Webpage
• Step1: Open text editor Notepad (click on Start → All Programs → Accessories Notepad)
• Step2: Enter the following lines of code:
• <HTML>
• <HEAD>
• <TITLE>
• My first Page
• </TITLE>
• </HEAD>
• <BODY>
• WELCOME TO MY FIRST WEB PAGE
• </BODY>
• </HTML>
• Saving and Viewing A HTML Document
• Step3: Save the file as myfirstpage.html (go to File → Save As → give File name:
myfirstpage.html.
• Choose Save As type: All Files → click save)
• Step4: Viewing document in web browser (open Internet Explorer-click on File-Open-Browse-select the
file myfirstpage.html → click open → click → OK 119
Text Tags & Character Formatting Tag
• Text Tags
• Text tag are divided into two categories as:
• Character-level tags and attributes
• which applies to formatting of individual letters or words.
• Paragraph-level tags and attributes
• which apply to formatting of text sections
• Character Formatting Tag
• The character formatting tags to specify how a
are usedtext should be displayed on the screen to distinguish
particular
certain characters within the 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

• Marquee Tag Ex:


• The <marquee> HTML element is used to insert a scrolling area of text. https://www.youtube.com/watch?v=HBCf2qDeVGQ
• This tag is used text horizontally across the screen. It is mainly used to deliver a specific message
to the visitor or
• Exampl <marquee>
to scroll Ads hello world
on a page.
• e:
Attributes </marquee>
of Marquee Tag
• Bgcolor:
• Sets the background color of the marquee.
• Direction:
• Sets the direction of the marquee box to either left-to-right, right-to-left, up-to-down
and down-to-up.
• Example1: <marquee direction = "right">This text will scroll from left to
right</marquee>
• Example2: <marquee direction = "up">This text will scroll from bottom to
up</marquee>
• Width:
• This sets how wide the marquee should be.
• Example: <marquee width = "50%">This example will take only 50% 133
width</marquee>
Paragraph Formatting Tag

• Paragraph Formatting Tag


• Paragraph level formatting applies to formatting of an entire portion of text
unlike
character level tags where only individual letters or words are formatted.
• Common Paragraph Formatting Tags
• Using paragraph tag: <P>
• This tag <P> indicates a paragraph, used to separate two paragraphs with a blank line.
• Example: <P> Welcome to the world of HTML </P>
• <P> First paragraph. Text of First paragraph goes here</P>
• Output:
• Welcome to the world of HTML
• First paragraph. Text of First paragraph goes here 125
Using Line Break Tag: <BR>
• The empty tag <BR> is used, where the text needs to start from a new line and
not to continue the same line.
• To get every sentence on a new line, it is necessary to use a line break.
• Example:
• <BODY> Data Inputs & Manipulations <BR>
• 200-IE-4, Level 2/4 <BR>
• Section 126/1283, Year 2022 </BODY>
• Output:
• Data Inputs & Manipulations
• 200-IE-4, Level 2/4
• Section 126/1283, Year 2022

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
©, ® &copy, &reg <PRE>
The copyright symbol is:
¼, ½, ¾ &frac14, &frac12, &frac34 &COPY;
÷, <, >, ≤,≥ &divide, &lt, &gt, &le, &ge The registered rank is: &REG;
</PRE>
& &amp 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: Practicing HTML Tags1============>


<!============> <HTML>
<!============> <HEAD>
<TITLE>
<!Comment: First Webpage> Hello
</TITLE>
<HTML> </HEAD>
<HEAD> <BODY>
WELCOME TO MY FIRST WEB PAGE
<TITLE> <br>
my name is neer <br>
MyName <b>i'm a student </b>
</TITLE> <br>
<i> My Course is Data Inputs </i> <br>
</HEAD> <u> I have done with Python </u>
<BODY> <br>
<b><i><u> All in One </u></i></b> <br>
This is MY First HTML Webpage! <h4><b><i><u><FONT COLOR="green"> Let's learn on color
</FONT></u></i></b></h4>
</BODY> <br>
</HTML> <FONT FACE="Algerian"> the text will be displayed in Arial</FONT>
</BODY>
<!============> </HTML>
<!
132
==========
Practice HTML (Contd) <!============>
<!Comment: Practicing: HTML
Tags3============>
<HTML>
<HEAD>
<TITLE>
My first Page - I start my work from here
</TITLE>
</HEAD>
<b> WELCOME </b>
<BODY>
WELCOME TO MY FIRST WEB PAGE
</BODY>
<BODY>
<br>
<b> WELCOME </b>
<BR>
<b> WELCOME </b>
<i> WELCOME </i>
<u> WELCOME </u>
<marquee> hello world </marquee>
<PRE>
Data Inputs & Manipulations
200-IE-4, Level 2/4
Section
126/1283, Year
2022
</PRE>
<! 133
Practice HTML (Contd) <!============>
<!Comment: Practicing HTML Tags
<HTML>
<HEAD>
<TITLE
>
MyKKU
</
TITLE>
</
HEAD>
<BODY
>
WELCO
ME TO
MY
FIRST
WEB
PAGE
<br>
This is
mu first
HTML
effort
</br>
Welco
me to
the
<i><B
>
Interne
t World
</B></
i>
<BIG>
hi
</BIG>
<br>
I<sub>
2</
sub>
<br>
<br>
<br>
I<sup>2</su
p> 134
<br>
<!
<FONT
==========
Practice HTML (Contd)
<!============>
<!Comment: Font Style>
<HTML>
<HEAD>
<TITLE>
MYPAGE
</
TITLE>
</
HEAD>
<BODY
>
<!Font
FACE
="Arial"
>
WELCO
ME TO
MY
FIRST
WEB
PAGE-
Font
Arial
</FONT
>
<!FONT
FACE="
Broadwa
y">
WELCO
ME TO
MY 135
FIRST
Practice HTML (Contd) <!============>
<HTML>
<HEAD>
<TITLE>
Use of Paragraph, Line break and preformatted text Tag
<!====PRACTICE QUESTION========> </TITLE>
<! Write HTML Text for the following OUTPUT in the following Webpage </HEAD>
Layout> <BODY>
1. HTML Learning - HTML stands for Hypertext Markup
is used forLanguage It page. It is very simple and easy
creating web 2.
to learn. HTML
Learning - HTML stands for Hypertext Markup Language
It is used for creating web page. It is very simple and easy
to learn.
<P>
HTML stands for Hypertext Markup Language
It is used for creating web page. It is very simple and easy
to learn.
<BODY>
Your horizontal rule goes here.
<HR> The rest of the text goes
here.
</BODY>
Output:
<HR ALIGN=' 'CENTER' '
WIDTH=' '50%' ' SIZE=' '3"
NOSHADE
COLOR="BLUE“>
<!============>
136
Practice HTML (Contd)

<!============>
<!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>

a pages of the entire site can link to.


HTML Different
(NOTE: Specific markup properties like Class to be discussed later).

• 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>

• External: the .css stylesheet file


<link rel="stylesheet" type="text/css" href=“mystylesheet.css" />

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.

• If you want to override inherited settings, body { font-family: Verdana;


font-size: 1.1em; }
you need to specify a style in a more local .littletext { font-size: 8px; }
element <body>
This text is larger.
<p class=“littletext”>This text is smaller.</p>
157
HTML vs CSS
• Webpage in HTML

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

Application, Small Projects CSS: Cascading Style Sheets


NOTE: any change shall be updated
SQL: Structured Query L1a5n6guage
MySQL is a Relational Database
Management System (RDBMS)
developed
by ORACLE Corporation that is based

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.

Return to MySQL Shell Prompt: mysql> Use ^C OR-> \c


MySQL Shell: mysql>
MySQL Command Prompt ->

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

• The MySQL Installation shall be done in THREE Steps


• Step1: MySQL Server (MySQL Community Server)
• Step2: MySQL Workbench
• Step3: MySQL Shell
• Install a Server: https://www.mysql.com/
• DOWNLOADS > MySQL Community (GPL) Downloads » > MySQL Installer for Windows
• Custom Installation: MySQL Server + MySQL Workbench + MySQL Shell

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)

• NOTE1: Most MySQL commands end with a semicolon ;


• NOTE2: MySQL returns the total number of rows found, and
the total time to execute the query.
171
Basic Queries (Contd)
• Keywords may be entered in any letter case
(small, capital, or mixed of small & capital).
• The following queries are equivalent:
mysql> SELECT VERSION(), CURRENT_DATE;
mysql> select version(), current_date;
mysql> SeLeCt vErSiOn(), current_DATE;
• Here's another query.
• It demonstrates that the MySQL can be used as a Simple Calculator:
mysql> SELECT SIN(PI()/4), (4+1)*5;
+ + +
| SIN(PI()/4) | (4+1)*5 |
+ + +
| 0.707107 | 25 |
+ + +

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 |
+ +

The NOW() function returns the current date 173


and time.
Return to MySQL Shell Prompt: mysql> -> ^C OR-> \c

Comments: Single Line & Multiple Lines


• Single Line Comment
• The syntax for a comment in a line of SQL code is a Double

Hyphen at the beginning of the line.



( --Line
Multi ) Comment
• The /* */
is the beginning of a comment and is the
comment.
end of MySQL will ignore (not execute) the above
comment.
• mysql determines where your statement ends by looking for
the terminating semicolon, not by looking for the end of the
input line.
• Canceling a Command: mysql> -> ^C -> \c
• If you decide you don't want to execute a command that you are in
OR the process of entering, cancel it by typing \c or ^C
mysql> SELECT
-> USER()
-> \c
mysql> 165
Using a Database
• To get started on your own database, first check which databases currently exist in your MySQL Server.
• Use the SHOW statement to find out which databases currently exist on the server:
mysql> show databases;
+ +
| Database |
+ +
| mysql |
| test |
+ +
2 rows in set (0.01 sec)

• To create a new database, issue the “create database” command:


mysql> create database YourName;
• To the select a database, issue the “use” command:

mysql> use YourName;


• Delete a Database

mysql> drop database


YourName; 175
Creating a Table
Showing Tables
• Once you have selected a database, you can view all database
tables: Showing Tables: mysql>show tables;
• An empty set indicates that you have not created any tables yet.
• Let’s create a table for storing pets' data.
• VARCHAR is usually used to store string data.
• To create a table, use the CREATE TABLE command: mysql> show tables;
Table Pet Empty set (0.02 sec)
Name VARCHAR(20)

Owner VARCHAR(20)

Species VARCHAR(20)

Gender CHAR (1)


Birth Date
Death Date

mysql> CREATE TABLE pet (


-> name VARCHAR(20),
-> owner VARCHAR(20),
-> species VARCHAR(20),
-> gender CHAR(1),
-> birth DATE, death DATE);
Query OK, 0 rows affected (0.04 sec)

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)

• Deleting a Table mysql> drop table pet;


• To delete an entire table, use the DROP TABLE command: Query OK, 0 rows affected (01.6802
Loading Data
• Use the INSERT statement to enter data into a table.
• Example: mysql>INSERT INTO pet VALUES ('Fluffy’,’John','cat',’f’,’2023-02-01',NULL);

Sample Data File (Load Data from


pet.txt)

Fluffy John cat f 2023-02-01 \N


Claws Gwen cat m 1994-03-17 \N
Buffy Harold dog f 1989-05-13 \N
Fang Benny dog m 1990-08-27 \N
Bowser Diane dog m 1979-08-31 1995-
07-29
Chirpy Gwen bird f 1998-09-11 \N
Whistle Gwen bird \N 1997-12-09 \N
r
• Loading Sample Data Slim Benny snake m 1996-04-29 \N
• Data can also be loaded from a ‘pet.txt’ (user create this file and do the following) file into MySQL Table.
• Create a text file ‘pet.txt’ containing one record per line.
• Here, all values must be separated by tabs and given in the order in which the columns were listed in the CREATE TABLE statement.
• Then load the data in the MySQL Table via the LOAD DATA Command. For each of the examples, assume the following set
• mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet; of data.

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.

• The SELECT statement is used to pull information from a table.


• The general format is for mysql>SELECT:
SELECT what_to_select
FROM which_table
WHERE
conditions_to_satisfy
• Selecting All Data
• The simplest form of SELECT retrieves everything from a table
mysql> select * from pet;
+ + + + + + +
| name | owner | species |gender| birth | death |
+ + + + + + +
| Fluffy | Harold | cat | f | 2023-02-01 | NULL |
| Claws | Gwen | cat | f | 1994-03-17 | NULL |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
| Fang | Benny | dog | m | 1999-08-27 | NULL |
| Bowser | Diane | dog | m | 1998-08-31 | 1995-07-29 |
| Chirpy | Gwen | bird | f | 1998-09-11 | NULL |
| Whistler | Gwen | bird | | 1997-12-09 | NULL |
| Slim | Benny | snake | m | 1996-04-29 | NULL |
+ + + + + + + 170
8 rows in set (0.00 sec)
Selecting Particular Rows
• You can select only particular rows from your table.
• Example: if you want to verify the change that you
made to Bowser's birth date, select Bowser's record like
this:
mysql> SELECT * FROM pet WHERE name = "Bowser";
+ + + + + + +
| name | owner | species | gender | birth | death |
+ + + + + + + NOW, If you don’t want to see entire rows from
| Bowser | Diane | dog | m | 1998-08-31 | 1995-07-29 | your table, just name the columns in which you are
+ + + + + + +
1 row in set (0.00 sec) interested, separated by commas.
Example: if you want to know when your pets
were born, select the name and birth columns.
mysql> select name, birth from
• To find all pets born after 1998 pet;
| name | birth |
+----------+------------+
mysql>SELECT * FROM pet WHERE birth >= "1998-1-1"; +----------+------------+
| Fluffy | 1999-02-04 |
| Claws | 1994-03-17 |
• To find all male dogs, use a logical AND | Buffy | 1989-05-13 |
| Fang | 1999-08-27 |
mysql> SELECT * FROM pet WHERE species = "dog" AND gender | Bowser | 1998-08-31 |
= “m"; | Chirpy | 1998-09-11 |
| Whistler | 1997-12-09 |
• To find all snakes or birds, use a logical OR | Slim | 1996-04-29 |
+ + +
mysql> SELECT * FROM pet WHERE species = "snake“ OR species = 8 rows in set (0.01 sec) 171
Sorting Data
• To sort a result, use an ORDER BY clause.
• Example: To view animal birthdays, sorted by date:
• NOTE: Here, DoB is sorted in the ascending order. To sort in reverse order, add the DESC (descending keyword)
mysql> SELECT name, birth FROM pet ORDER BY birth; mysql> SELECT name, birth FROM pet ORDER BY birth DESC;
+ + + + + +
| name | birth | | name | birth |
+ + + + + +
| Buffy | 1989-05-13 | | Fang | 1999-08-27 |
| Claws | 1994-03-17 | | Fluffy | 1999-02-04 |
| Slim | 1996-04-29 | | Chirpy | 1998-09-11 |
| Whistler | 1997-12-09 | | Bowser | 1998-08-31 |
| Bowser | 1998-08-31 | | Whistler | 1997-12-09 |
| Chirpy | 1998-09-11 | | Slim | 1996-04-29 |
| Fluffy | 1999-02-04 | | Claws | 1994-03-17 |
| Fang | 1999-08-27 | | Buffy | 1989-05-13 |
+ + + + + +
8 rows in set (0.02 sec) 8 rows in set (0.02 sec)

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:

mysql> SELECT * FROM pet WHERE name REGEXP


+
"fy$"; + + + + + +
| name | owner | species | sex | birth | death |
+ + + + + + +
| Fluffy | Harold | cat | f | 1993-02-04 | NULL |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
+ + + + + + + 174
Counting Rows
• Counting Rows
• Databases are often used to answer the question, "How often
does a certain type of data occur in a table?"
• Example: You might want to know how many pets you have, or how many pets each
owner has.
• NOTE: Counting the total number of animals, you have is the same question as “How many
rows are in the pet table?” because there is one record per pet.
• The COUNT() function counts the number of non-NULL results.
• Counting Rows Example:
• A query to determine total number of pets: mysql> SELECT COUNT(*) FROM pet;
+ +
| COUNT(*) |
+ +
| 9 |
+----------+ 175
Batch Mode
• Batch Mode:
• Reading commands from a file is called running in batch mode.
• NOTE: Up to here, the mysql has been used interactively to
enter queries and view the results.
• Batch Mode:
• Now, you can also run mysql in batch mode.
• To do this, put the commands you want to run in a file, then tell mysql to
read its input from the file:
shell> mysql < batch-file

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

• Q1: What are the Applications of MySQL


• MySQL is a relational database management system based on SQL–
Structured Query Language.
• The application is used for a wide range of purposes, including
• data warehousing,
• e-commerce, and
• logging applications.
• web database
• Q2: Are Python and SQL the same?
• SQL is a query language that is used to access and extract data from a
database. Python is a general-purpose programming language that
facilitates data experimentation.
• Q3: What are the differences between SQL and MySQL?
• One is a language, while the other is database software.
• SQL is the programming language to query a database.
• MySQL is an open-source database product that enables users to keep
this data organized. 178
Thanks
• Summary
• Using the MySQL Shell
• Creating Tables
• Creating basic SQL Queries
• SQL provides a structured
language for
querying/updating multiple databases.
• The most important part of SQL is learning to
retrieve data.
• selecting rows, columns,
boolean operators, pattern matching, etc.
• Keep playing around in the MySQL Shell.

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

Commercial Application, Small CSS: Cascading Style Sheets

Projects NOTE: any change shall be updated


SQL: Structured Query L1a8n1guage
Commercial Software
• What Does Commercial Software Mean?
• Commercial software is any software or program
that is designed and developed for licensing or
sale to end users or that serves a commercial
purpose. Commercial software was once
considered to be proprietary software, but now
a number of free and open-source software
applications are licensed or sold to end users.
Off-the-shelf software programs, such as games
or those sold in computer specialty stores or
even music stores and grocery stores, are some
examples of commercial software.
• Example: Microsoft products such as
Windows Operating System and MS Office are
the
some of the most well-known examples of
commercial software.
182
Difference between Open-Source Software
and Commercial Software
• 1. Open-Source Software
• Open-Source software is the computer software developed either by an individual, group or an
organization to meet certain requirements and it is available for any modifications based on its developing
body’s interest. Open-Source software is published openly for general public and here the source code is
open for all. For open-source software the users do not need to spend any cost. It is available under free
licensing. It depends on donations and support as its main source of find. It is also known as Custom
Software (Source Code, available).
• Examples: Firefox, OpenOffice, Zimbra, VCL media player, Thunderbird.
• 2. Commercial Software
• Commercial software is the computer software where only the person, team, or organization that created
it can modify also they have exclusive right over the software. Anyone needs to use it has to pay for it valid
and authorized license. Here the source code is protected. For commercial software the users need to
spend moderate to expensive cost. It is available under high licensing cost. It depends on its software sale /
product licensing as its main source of fund. It is also known as Closed Software (Source Code, NOT
available).
• Examples: Windows Operating System, MS Office, SAP, Oracle, Adobe Photoshop. 183
Difference between Open-Source Software
and Commercial Software (Contd)
S.No. OPEN-SOURCE SOFTWARE COMMERCIAL SOFTWARE
Open-Source software is the computer software developed
Commercial software is the computer software where only the person,
either by an individual, group or an organization to meet certain
01. team, or organization that created it can modify also they have exclusive
requirements and it is available openly for general public for
right over the software. Anyone needs to use it has to pay for it valid and
any modifications based on its developing body’s interest.
authorized license.
02. The cost of open-source software is free. The cost of commercial software varies from moderate to expensive.
03. Open source provides limited technical support. Commercial software provides guaranteed technical support.
04. Open-source software is available under free licensing. Commercial software is available under high licensing cost.
05. In open-source software users need to rely on community support. In commercial software users get dedicated support from the vendor.
In open-source software installation and updates are administered by
06. In open-source software installation and updates are administered by
the software vendor.
the user.
Limited hands on training and online resources are available for On site and Online trainings are available from the commercial software
07.
open-source software application training. vendor side for software application training.
08. Here in open-source software users can customize. But in commercial software mainly vendor offers customization.
09. In this rapid community response helps in fixing the bugs and In this mainly the vendor is responsible for fixing the malfunctions.
malfunctions.
10. In open-source software the source code is public. In commercial software the source code is protected.
The source of funds of open-source software mainly depends on The source of fond of commercial software depends on its software sale
11.
donations and support. / product licensing.
Firefox, OpenOffice, Zimbra, VCL media player, Thunderbird Windows Operating System, MS Office, SAP, Oracle, Adobe Photoshop
12. 184
are some examples of open-source software.
Thanks

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)

#Q5 Example5: Develop a flowchart to find whether a Number is POSITIVE or NEGATIVE.


a=int(input("Enter
A:")) if a > 0:
print("POSITIVE")
else:
print
("NEGATIVE")

202
Online Compiler
• print(type("hello"))
• print(type(2+8j))
• print(type(2.20))

203

You might also like