KEMBAR78
CL - Notes | PDF | Computer Network | Network Switch
0% found this document useful (0 votes)
39 views22 pages

CL - Notes

The document discusses various topics related to computer networks including local and wide area networks, network categories, network topologies, data transmission methods and devices, basic internet concepts, and applications of computer networks. It provides details on peer-to-peer and client-server networks, different network devices and their functions, and emerging technologies like artificial intelligence and the internet of things.

Uploaded by

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

CL - Notes

The document discusses various topics related to computer networks including local and wide area networks, network categories, network topologies, data transmission methods and devices, basic internet concepts, and applications of computer networks. It provides details on peer-to-peer and client-server networks, different network devices and their functions, and emerging technologies like artificial intelligence and the internet of things.

Uploaded by

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

Computer Literacy Notes

19/4 Friday

Content Page
1 - Introduction to Computer Networks 2
1.1 Local Area Networks (LANs) and Wide Area Networks (WANs) 2
1.2 Network Categories 2
1.3 Network Topologies 2
2 - Data Transmission in Computer Networks 3
2.1 Connecting Devices 3
2.2 Network Cables for Wired Network Transmission 5
2.3 Wireless Data Transmission 7
2.4 Network Security 9
2.5 Build a Simple Network 10
3 - Basic Concepts of the Internet 11
3.1 Internet Protocol (IP) Address 11
3.2 Domain Name System (DNS) 12
3.3 Uniform Resource Locator (URL) 12
3.4 Web Hosting 14
4 - Application of Computer Networks 15
4.1 e-Commerce 15
4.2 e-Learning 15
4.3 e-Government 16
4.4 e-Entertainment 16
4.5 Internet of Things (IoT) 16
4.6 Big Data 17
5 - Era of Artificial Intelligence 17
5.1 Artificial Intelligence is Everywhere 17
5.2 How Artificial Intelligence is Changing the World 17
5.3 From Blockly to Python 17
5.4 Python Development Environment 18
5.5 Text-to-Speech (TTS) 18
6 - Super Translation Gadget 19
6.1 Translation Device 19
6.2 Variables 19
6.3 Keyboard Input 20
7 - Smart Assistants 20
7.1 Virtual Assistants 20
7.2 Speech Recognition 21
3.3 Smart Light 21
3.4 Natural Language Processing Technologies 22

1
1 - Introduction to Computer Networks
1.1 Local Area Networks (LANs) and Wide Area Networks (WANs)
LAN (Local Area Network) WAN (Wide Area Network)

Coverage Small Large

Example Home network, School Network Military Network, The Internet

1.2 Network Categories

➢ In a computer network, data is sent and received by different devices. The role of the devices
are decided by the network structures.
➢ There are two main categories of LANs:

Peer-to-Peer Networks Client/Server Networks

Description Share the same resources and privilege Centralized administrative system
without a centralized administrative (server) is present.
system. → Connect and make requests The server shares files and resources
directly with one another to clients connected to it

Example BitTorrent (BT): communication protocol Social Media.


for P2P file sharing. Post photo → Request made in
Used for downloading large files. server → Process → Uploaded

Advantage ➢ Low cost ➢ Better user management


➢ Easy to set up ➢ More secure
➢ Flexible, easy to add or remove ➢ Data back-up and recovery
device is easier

Disadvantage ➢ Less secure ➢ High cost


➢ Difficult to organize a large ➢ Difficult to set up and
number of files maintain

1.3 Network Topologies

➢ Network topology: layout of a


network
➢ Physical topology: how devices in a
network are wired together
➢ Logical topology: how data is
transmitted within a network

2
Limitations of some of these topologies

➢ Ring: failure of a single node or link can disrupt the entire network.
➢ Bus: suffer from reduced bandwidth and increased latency as data must pass through each
node in the ring.
➢ Mesh: requires a large number of connections and can be expensive to implement and
maintain.
➢ Star: failure of the central hub can result in the entire network becoming inaccessible.

2 - Data Transmission in Computer Networks


2.1 Connecting Devices

Network Interface Card (NIC)

➢ Enables device to exchange data through a network


➢ Installed inside a network device (e.g. computer or router)
○ Connected to the motherboard of computer through peripheral computer interconnect
(PCI) slot, while others use USB connection
➢ Wireless NICs are commonly equipped with USB and antennae → improve signal reception
➢ Each NIC has a 48-bit unique Media Access Control (MAC) address → identify device
connected to the network.
○ MAC network aka physical network, stored in hardware

How does NIC work?

The NIC is like a special part of your toy telephone that helps it send and receive messages to other
toy telephones or computers. It converts your voice or messages into special signals that travel
through the wires or air, and it listens for signals from others and turns them into words or messages
you can understand. It's like a little helper inside your toy telephone that lets it talk to others and
understand what they're saying.

Hub and Switch

➢ Hub: connection point of different devices in the same LAN. Data entering a hub is forwarded
to all devices connected to it.
➢ Switch: connects different devices within the same LAN and directs data to targeted devices
based on their MAC address. Besides, package buffering in the switch prevents data collision.

3
Hub Switch

Security Low High


Data packets are transmitted to Data packets are transmitted to specific
every port ports

Efficiency Low High


Transmits one data packet at a time Transmits multiple data packets at a time

Network Speed Same network speed for each port Each port has specifically allocated
network speed

Bridge

➢ Similar to a switch, but connects fewer LANs


➢ E.g. homeplug (bridge) connects a LAN to Ethernet and the powerline

Router

➢ Link between LANs or a LAN and a WAN and finds the shortest path to the destination for
data packets.
➢ Router can connect LAN to the Internet → commonly found nowadays

Commercial and Home Routers

Similarity Difference

Both can convert different types of Home routers are all-in-one with multiple functions.
networking signals E.g. wireless network hosting

Both can link between LANs Home routers handle less data

Both can link a LAN to the Internet Home routers have lower efficiency in processing data

Firewall

➢ Prevents illegitimate access from or to a computer on the Internet


➢ Screens every message transmitted through the network and filters the harmful ones
➢ Can be hardware or software. Routers sometimes have the hardware function as well

Access Point

➢ Provides wireless connection through Wi-Fi


➢ Routers for home and office use also serve as access points

4
Modem

➢ Device used to convert between analog signals (telephone lines or television cables) and
digital signals (computers)
➢ Provided to users by Internet Service Providers (ISP) for Internet connection.

Dial-up Modem

➢ Most traditional type. Converts between digital and analog signals, so that data can be
transmitted through a telephone line.
➢ As dial-up modems only support a maximum transmission speed of 5 Kilobits per second →
mostly replaced by other types

Digital Subscriber Line (DSL) Modem

➢ Provides broadband Internet connection


➢ Converts signals for transmission through telephone lines but uses a wider frequency.
➢ Most ISPs provide Internet service with DSL modem using an Asymmetric Digital Subscriber
Line (ADSL) → download speed significantly faster than upload speed, to maximize
bandwidth usage.
➢ Transmission speed of DSL: 8 Mbps

Cable Modem

➢ Makes use of coaxial cables that transmit cable television signals to provide Internet access.
➢ For Internet service using cable modems, the bandwidth is shared with the entire building →
network speed vary throughout the day
➢ Transmission speed: can go over 100 Mbps

Fibre Optic Modem

➢ Optical network terminal (ONT) that converts between light signals and electrical signals to
transmit and receive data in an optical fibre network
➢ Allow users enjoy high-speed Internet connection.

2.2 Network Cables for Wired Network Transmission

Twisted Pair Cable

➢ Contains pairs of wire twisted together → reduce electromagnetic interference (EMI) and
crosstalk (noise from nearby wires)
➢ Mainly two types of twisted pair cables:

5
Unshielded Twisted Pair (UTP) Cable

➢ Consists of four pairs of wire twisted together, e.g. Cat5 and Cat5e cables (for network)
○ Maximum transmission speed of an unshielded Cat5 cable: 100 Mbps
○ Maximum transmission speed of an unshielded Cat5e cable: 1 Gbps
➢ To connect a cable to a device, a connector is used. (RJ45)
➢ To increase the coverage of twisted pair cables, we can use a repeater to connect them tgt.

Shielded Twisted Pair (STP) Cable

➢ STP cables are similar to UTP cables, except that they are enclosed by a metal shielding.
➢ STP cables offer more protection from EMI and crosstalk → more expensive

Coaxial Cable

➢ Contains a conducting copper wire core surrounded by insulating materials and braided wires
that is enclosed by a plastic tube cover
➢ Commonly used in computer networks with bus topology.

Optical Fibre Cable

➢ Silica tube that carries light beams using total internal reflection
➢ High transmission speed and can serve long transmission distances as the amount of data loss
is small. An optical transceiver is used to convert between optical signals (transmission) and
electrical signals (computer use).

Advantage Disadvantage

UTP Cable ➢ Low cost ➢ Used over a short distance


➢ Easy to install ➢ Affected by EMI

STP Cable ➢ Faster transmission speed ➢ Higher cost


compared to UTP ➢ Used over a short distance (<100
➢ Less affected by EMI meters, same as UTP)

Coaxial ➢ Easy to install ➢ Cable pipes take up a lot of space


Cable ➢ Compatible with cable TV ➢ Cannot withstand sharp bending

Optical ➢ Fastest transmission speed ➢ Very high cost


Fibre Cable ➢ Not affected by EMI ➢ Hard to install
➢ Less distance restriction

6
2.3 Wireless Data Transmission

Long-distance Wireless Data Transmission

Wi-Fi

➢ Wireless data transmission that uses radio waves to transmit data


➢ Based on IEEE 802.11 standards
➢ LAN that offers WiFi access is often called a wireless LAN (WLAN)
➢ Access points and wireless routers provide Internet connection via Wi-Fi

802.11a 802.11b 802.11g 802.11n 802.11ac

Maximum Data 54 Mbps 11 Mbps 54 Mbps 600 Mbps 1 Gbps


Transmission Rate

Frequency 3.7 / 5 GHz 2.4 GHz 2.4 GHz 2.4 / 5GHz 5 GHz

Year of Deployment 1999 1999 2003 2009 2013

Wi-Fi 6 is the latest standard for Wi-Fi networks. It has larger bandwidth, which enables users to
upload and download data at a higher speed. It allows more users to connect to a Wi-Fi hotspot at the
same time, supporting high-speed wireless Internet access in densely populated areas.

A Dual Band Router can support both 2.4 GHz and 5 GHz Wi-Fi signals simultaneously. Nowadays,
as many computer-related wireless devices, e.g. bluetooth earphones and wireless mice, use the 2.4
GHz frequency, they might interfere with one another. Hence, 5 Ghz Wi-Fi is created. Although its
geological coverage is smaller, it has a higher network stability.

3G and 4G Mobile Networks

➢ The Third and Fourth generations of cellular network technology


➢ Transmission speed of 3G: 384 kbps - 42 Mbps
➢ Transmission speed of 4G: 600 Mbps

5G is the fifth generation of cellular network technology. It adopts the newest data transmission
modes that allow a much faster data transmission (10 Gbps). It has larger capacity and lower latency
and can connect a lot of devices at once. This helps facilitate the application of augmented reality
(AR) and virtual reality (VR) technologies and development of smart cities.

7
Satellite Communication

➢ Cover places where wired connection is inaccessible.


➢ A communication satellite orbiting in space receives signals from an earth station, amplifies
the signals and sends them back to another earth station
➢ Allows ISPs to provide Internet access in remote areas.

Worldwide Interoperability for Microwave Access (WiMAX)

➢ Use microwave signals to build Internet connection


➢ A straight connection between a microwave receiving device and the access point installed on
the top of the building has to be established.
➢ Microwave broadband signals are easily affected by the weather. Rainstorm and windstorm
could weaken, or even stop the signals.

Short-distance Wireless Data Transmission

Bluetooth

➢ Commonly used for data transmission between mobile devices


➢ Very popular due to its convenience and high compatibility
➢ Transmission speed of Bluetooth 5.0: 24 Mbps.

Radio Frequency Identification (RFID)

➢ RFID is a wireless and contactless system, sending data by radio frequency.


➢ As RFID labels can be detected within a few meters and read from any angle, there are certain
security risks.
○ RFID-blocking card holders and wallets are invented → prevent sensitive information
from being skimmed.
➢ Near Field Communication (NFC), is an extension of RFID. Can transfer a large amount of
data and support two-way data transfer for devices, but is short-distance.

Zigbee is a network standard commonly used in low-powered devices. It helps connect Internet of
Thing (IoT) or smart home devices like sensors, light bulbs and switches.

8
2.4 Network Security

Encryption

➢ Wi-Fi networks protected by Wired Equivalent Privacy (WEP) can be cracked within minutes
→ introduce security protocols, e.g. encryption, to enhance the security of Wi-Fi networks.
➢ Wi-Fi Protected Access (WPA) is a security protocol addressing the weakness of WEP.
○ Adopts the Temporary Key Integrity Protocol (TKIP), which encrypts data using a
changing key, making it more difficult to crack.
➢ A newer and more complex version of WPA, WPA2, is also commonly used nowadays.

Hide Service Set Identifier (SSID)

➢ Service Set Identifier (SSID) is a customisable name given by users to a Wi-Fi network.
➢ To protect your home Wi-Fi network, you can disable the SSID broadcast of the Wi-Fi
network, so the network cannot be scanned by devices automatically to prevent unwanted
access.

MAC Address Filtering

➢ MAC address filtering heightens network security by restricting unauthorized access to a


Wi-Fi network.
➢ As the MAC address of a device is fixed →> set a whitelist → only devices with MAC
addresses on it can connect to the network.

Use Public Wi-Fi Carefully

➢ Avoid using public Wi-Fi hotspots for private purposes, e.g. online banking and stock trades.
➢ Anyone can connect to public networks, hackers may hack into the network and monitor
traffic going through the network.
➢ 3G/4G are considered more secure, only the user and the telecommunication provider will be
using the network, but still have security risks.

9
2.5 Build a Simple Network

Key:

➢ PSK: password for connecting to the network


➢ Connection Mode: IEEE 802.11 standards the router supports
➢ Security Mode: Wireless encryption protocol, WEP, WPA and WPA2

Connecting the Cables

1. Connect the computer and the LAN port of the wireless router with a network cable
2. Connect the WAN port of the wireless router and the modem/another router with a network
cable.

Log in to the wireless router

3. Enter the IP address marked on the label of the router


4. Log in using the username and password stated on the label of the router
5. Go to Network Setup → WAN/Internet → Connection Type
6. Select Dynamic IP. For D-Link, go to Setup - Wireless Settings

Check if the computer can connect to the Internet

7. Open Command Prompt


8. Enter “ping” + a website. This command tests the time needed to send four packets to a
website.

Configure Wireless Network

9. Go to Wireless - Wireless Settings


10. Enter a name for SSID / Wireless Network Name
11. Select WPA-PSK / WPA-Personal then enter a PSK Password
12. Connect the laptop / smartphone to the wireless network by choosing the network name and
entering the password through Wi-Fi section in the laptop / smartphone
13. Open the web browser and try to connect to the website

10
3 - Basic Concepts of the Internet
3.1 Internet Protocol (IP) Address

➢ When data is transmitted across computer networks, the addresses of the data source and
destination are appended to the message. These addresses are called IP addresses.
➢ IP address: changeable numerical address used to identify a device in a network.
➢ When a device connects to the Internet, an IP is assigned by the Internet Corporation for
Assigned Names and Numbers (ICANN) through your ISP.

IPv4

➢ 32-bit. Formed by four 8-bit numbers (octet) that are separated by a period.
➢ Range: 0.0.0.0 to 255.255.255.255 (Decimal).
➢ No. of available addresses: 232

Classes of IPv4 Address

Class A Class B Class C

Address Beginning 1-126 128-191 192-223


(decimal)

Address Beginning 1 10 110


(binary)

Default Subnet 255.0.0.0 255.255.0.0 255.255.255.0


Mask1

No. of Hosts 223-2 216-2 28-2

IPv6

➢ As IPv4 addresses are going to be used up → IPv6 is introduced as the successor protocol
➢ 128-bit. Formed by 8 16-bit numbers that are separated by a colon.
➢ Range: 0:0:0:0:0:0:0:0:0 to ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff (hexadecimal)
➢ No. of available addresses: 2128

1
special code that helps computers on a network know which part of an IP address belongs to the network and
which part belongs to the individual computer. It's like a tool that separates and organizes the addresses so that
the computers can communicate with each other correctly.

11
3.2 Domain Name System (DNS)

➢ Host Name: www (indicating the specific device under the network)
➢ Third-Level Domain: edb/google/youtube (indicating the domain network)
➢ Second-level domain: com/org/gov (indicating organization)
➢ Top-level Domain: hk/cn/jp (indicating country)

Name Resolution through a DNS server

➢ DNS is used to translate domain names into IP addresses → “name resolution”


➢ Location of a DNS server is expressed in IP address and can be changed to another server
➢ Although ISPs often provide their own DNS server to subscribers, there are also public DNS
servers available. E.g. Google Public DNS (8.8.8.8)
➢ You can use the IP address to browse a website, but usually use DNS → easier

Domain Name → DNS Server (e.g. 8.8.8.8) → IP Address (216.58.221.132)

3.3 Uniform Resource Locator (URL)

https://www.hku.hk:80/about/pm.html

Network Protocol (https://)

➢ Set of rules for network communication


➢ Both the client program and the server will have to follow the same rule in order to establish a
successful connection.

Domain Name (www.hku.hk)

➢ Unique representation of an IP address on the Internet. It is registered in the DNS.

Port Number (:80/)

➢ Actual network port that the computer is accessing


➢ When it is omitted, the browser will automatically access through the default port for HTTP
which is port 80.
➢ Other common well-known ports (reserved ports) include ports 20 and 21 for File Transfer
Protocol and Port 53 for Domain Name System (DNS)

Location

➢ Specific resource on the specific network

12
Examples of Location

➢ /computer
○ Folder name
➢ /computer/information_techn
○ Refers to a folder called “information_techn” under the folder “computer”
➢ /index.html
○ File name, if the file name is not specified in the URL, it will look for it by default

Types of Network Protocols

HTTP and HTTPs

➢ Hypertext Transfer Protocol (HTTP) is used by the World Wide Web (WWW) to transfer
hypertext web pages.
➢ When a user uses a web browser to browse a website, the browser acts as an HTTP server on
the destination domain. The HTTP server responds to these commands and transfers the
required web pages to the browser.
➢ HTTPS is a more secure version of HTTP, which makes use of Transport Layer Security
(TLS) encryption. It encrypts data during the transmission process to ensure confidentiality,
reliability and privacy of communication between clients and servers. It is commonly used in
trading and transmission of private information on the Internet.

FTP

➢ File Transfer Protocol (FTP) transfers files over a computer network.


➢ An FTP connection involves two parties, the file server and the client.
➢ Authentication is usually required to log into an FTP server.

SMTP

➢ Simple Mail Transfer Protocol (SMTP) regulates mail sending from mail servers
➢ Mail servers rely on SMTP to distribute mail to different mail servers.

IMAP/POP3

➢ Internet Message Access Protocol (IMAP) and Post Office Protocol - Version 3 (POP3)
regulate mail receiving in mail servers.
➢ IMAP: mail will be retained in the mail server after it is received.
➢ POP3: mail server will delete the mail after its first receipt.

13
Operation of different protocols

3.4 Web Hosting

To make a website, you will have to design the web pages and host them on a web server!

Free Web Hosting Service

➢ Free web hosting service providers provide web design tools and templates and allow users to
host web pages for free. E.g. Wix and Squarespace.

Paid Web Hosting Service

➢ Allow users to host web pages on their servers with advanced features, e.g. customizable
domain name and e-commerce functionality.

Home Server

➢ Host a website at home using a home server by having the appropriate router settings,
registering a domain and installing a web server software.

Free Web Hosting Service Paid Web Hosting Service Home Server

Pros ➢ No cost ➢ Professional support ➢ Full control over the


➢ Easy to set up ➢ More features server
➢ More bandwidth and storage

Cons ➢ Less user support ➢ High cost ➢ Difficult to set up


➢ Limited bandwidth and ➢ Requires
storage self-maintenance
➢ Cannot customize
domain name

14
4 - Application of Computer Networks
4.1 e-Commerce

Online Shopping

➢ People can purchase different types of products on the Internet, including computer software,
mobile phone applications, and physical goods such as books, etc.

e-Payment

Octopus Card

➢ Adopt the NFC technology and allow you to go cashless.


➢ Used on public transport, retail shops, websites, can top up card electronically or with cash

Credit Card

➢ Apply RFID or NFC technologies to support contactless payment → tap on reader


➢ Visa: PayWave; Mastercard: Contactless

Online and Mobile Payment

➢ E.g. PayPal and Alipay → purchase with ease


➢ Can make mobile payments by linking our credit cards to digital wallet in our mobile devices.
➢ Can Support QR code now as well → connect to Internet to process transaction info

Small Office / Home Office (SOHO)

➢ Data and resources are shared through a computer network.


➢ Can be shared through the Intranet as well.

Video Conferencing

➢ Facilitate home office, e.g. Zoom and MIcrosoft Teams → conduct video conference

4.2 e-Learning

Learning Management System (LMS)

➢ Electronic classroom resources are uploaded onto an e-platform to facilitate effective and
interactive learning. E.g. tablets,smartphones → conduct activities and get feedback

15
Mass Open Online Course (MOOC)

➢ Make knowledge affordable and easy to access and encourage people from different
backgrounds to learn. Many well-known institutions (e.g. Harvard and MIT) offer courses on
MOOC providers like edX and Coursera → for free, only pay if get certificate

4.3 e-Government

➢ Provision of public service on the Internet


➢ GovHK is the portal website of the HKSAR government that provides information on
different e-government services for the public.

e-Channel

➢ Automated Immigration is a self-service immigration clearance service


➢ Eligible HK resident insert smart HKID card into the card reader to enter the e-Channel →
place her finger on the fingerprint scanner → reduce time needed to pass immigration

4.4 e-Entertainment

Online Games

➢ Rely on user’s immediate response → importance of quality of network connection, stability


and time delay to provide a good gaming experience
➢ Network speed affect user experience when downloading and updating games

Streaming

➢ Streaming: Continuous transmission of an audio or video from one party to another


➢ Allows us to listen to an audio or watch a video without downloading its entirety.
➢ Only a short part of the audio or video needs to bed downloaded for buffering.

4.5 Internet of Things (IoT)

➢ Refers to a network connecting different objects, such as household appliances.

If This Then That (IFTTT)

➢ Online platform that helps integrate different types of services


➢ Users can create cross-platform instructions and commands to increase productivity.

4.6 Big Data

16
➢ Every photo and every post on the Internet is recorded and combined into the database of big
data. Through analyzing and reading the records, we can build a more advanced society by
improving the practices in different fields, e.g. commerce, medical services and research.
○ Companies learn about the interest & needs of customers by analyzing their browsing
or shopping records and attract them by providing relevant information like ads.
○ Medical staff can speed up diagnosis and devise effective treatment plans.
○ Give accurate weather forecasts, and predictions of extreme weather like typhoons.
○ Investors can make better investments to maximize their profit.
➢ With IoT, data can be collected through wearable devices, e.g. smartwatches.
➢ Potential Risks of invading personal privacy.

5 - Era of Artificial Intelligence


5.1 Artificial Intelligence is Everywhere

➢ AI: intelligence of machines, product of humans


➢ Machines can simulate humans’ thinking and cognitive function using computer programs
and learn from experiences in order to make decisions like humans.

5.2 How Artificial Intelligence is Changing the World

➢ AI and automation may gradually replace some occupations which consist of simple,
repetitive tasks and do not require creativity, e.g. waiters, drivers and accountants.
➢ No matter how clever and efficient the AI becomes, humans can still outperform it for our
creative thinking and empathy.
➢ AI can also bring new career opportunities for humans, e.g. AI engineers.

5.3 From Blockly to Python

➢ Visual programming allows us to write programs by arranging visual elements, which makes
reading and writing programs easier.
➢ Textual programming offers more flexibility for programming, you can specify the duration
for showing the icons by adding a parameter to the function.

5.4 Python Development Environment

17
Using Google Colab

➢ Colab is a Python program editor provided by Google.


➢ We can write and execute Python programs on a web browser. It also allows us to use a wide
range of libraries in Python without going through complicated procedures.

Start learning Python from Hello World!

➢ print(“Hello World!”)

Sequence

➢ In computational thinking, the order of execution in a program is called sequence


➢ From TOP to BOTTOM → check to avoid bugs

Importance of Syntax

➢ Must follow otherwise the programme cannot run on the computer


➢ The computer is unable to understand the code

Why choose Python?

➢ Make code concise and readable for easier learning and understanding.
➢ Function library with abundant resources, e.g. graph-tool.

5.5 Text-to-Speech (TTS)

➢ Makes use of AI. Convert text to natural and fluent speech as if a real human is speaking.
➢ Many applications and system provide a TTS function → convenient

import tts
import time
tts.say(“Hello World”)
time.sleep(2)

➢ Import Library → allow us to use the text-to-speech on the Google Cloud Platform
➢ time.sleep → pause; If X import → X execute

print(“Hello World!”)

➢ Function Name: print


➢ Input parameter: “Hello World!”

18
Adding Intonation

tts.say(“Hello, how are you?, pitch=-5, speaking_rate=0.5)

➢ Valid range of parameter pitch is -20.00 to 20.00;


➢ Valid range of parameter speaking_rate is 0.25 to 4.00

Biliterate and Trilingual

➢ Adding a parameter lang to the function say ().


○ Eng: “en-uk”
○ Cantonese: “yue-HK”
○ Putonghua: “cmn-CN”

6 - Super Translation Gadget


6.1 Translation Device

import cloudtranslation
chloudtranslation.translate(“how are you”)

➢ We must rewrite the programme whenever we want it to translate new content.


➢ We can refer to some translation tools, which use the same program to process different text
inputted by the user. Simply need to change the next in input bar to new content.

6.2 Variables
x = “Hello World”
print (x)

➢ The process of putting data into specified variables is called assignment.


➢ Variables can store values, can be read in different operations and can be changed.

Declaration of Variables

➢ We must declare the name of any variable that we are going to use.
○ Only sart with English letters (A-Z, a-z) or an underscore (_)
○ Only English letters, numbers and underscore can be used. “Whitespace” or other
symbols must not be included.

19
○ We cannot use “keywords / reserved words” as variable names. E.g. import, if, class,
and names of defined functions.

Calculating Math in Python


len = 19
area = len*len
print (area)

➢ Use VARIABLES; there are some arithmetic operators:


○ Addition: + ○ Multiplication: *
○ Subtraction: - ○ Division: /

6.3 Keyboard Input


lastname = input(“What is your lastname?”)
nickname = input(“What is your lastname?”)
print (“Hello”, nickname, lastname)

➢ “Hello” → String
➢ nickname,lastname → Variable

7 - Smart Assistants
7.1 Virtual Assistants

➢ Virtual assistant is a kind of AI software that provides users with different services and
supports. Simply give instruction → Complete various tasks.
➢ AI has promoted the development of numerous chatbots. They use conversation models to
perform tasks like answering questions from users, providing advice, etc.
➢ Applied in various industries, e.g. customer service, sales and education.
➢ Usually use the technologies of speech recognition and Natural Language Processing.
○ Speech Recognition: recognize user’s speech
○ NLP: analyze the speech and understand its structure and meaning

AI Chatbots Rule-based Chatbots

Technologies Natural language processing, machine learning Pre-defined rules

Responses Make adjustments based on users’ intention Can only make fixed responses
and feedback, resulting in more human-like based on predefined statements
responses

Applications Virtual assistants, smart homes Simple customer service

20
7.2 Speech Recognition

➢ We can identify the voices of different people because a human’s voice generates different
pitches (frequencies) and volumes (amplitude), forming a unique wave.
➢ Such features can be captured by machines through digitalization.
➢ After training and learning, a machine can identify the digital wave of each word → detect
pattern → identify words → “speech-to-text”’.
import cloudspeech, display
print(“Recording…”)
cloudspeech.record(5)
print(“Stop recording”)
display.showWaveform()

➢ Since our sound wave is analog data, the computer converts this analog data into digital data
with the two steps of discretization and quantization.
import cloudspeech
print(“Say something…”)
text = cloudspeech.recognise()
if text == None:
print(“Sorry I can’t hear you.”)
else:

print(“You said:”, text)

➢ Since the cloud speech service has not received any speech, it cannot return any string and the
final value of variable text is None (None is not a string).
➢ Data validation must be performed before the variable value is displayed.
➢ Hence, we need conditional statements.

Relational Operators

➢ == → Equal to
➢ != → Not equal to

Indentation: Very important syntax → shows the logical structure of program by indicating branch to
which the statements belong.

3.3 Smart Light

➢ Nowadays, we can control the lighting in our homes simply by picking up our smartphone
and tapping a button on the screen or giving a simple voice instruction.
➢ A smart home can be created with the help of technology.

21
import display
text = input(“Turn your light:”)
if text == “on”:
display.showImage(“light_bulb_on.png”)
if text == “off”:
display.showImage(“light_bulb_off.png”)

3.4 Natural Language Processing Technologies

➢ Natural Language Processing (NLP) is an AI technology that integrates linguistics and


machine learning in the analysis, processing and generation of natural language.
➢ Allow computers to understand human language.
➢ Various grammar rules and structures, a word may have multiple explanations and meanings
→ textual analysis, information extraction and sentiment analysis

“if…elif” conditional statement

➢ When condition 1 is true, instruction 1 is executed.


➢ When condition 1 is false and condition 2 is true, instruction 2 is executed.
➢ When both condition 1 and condition 2 are false, this conditional statement ends.

Nested Conditional Statement: Place one or more conditional statements into a branch of another
conditional statement.

Syntax Error Logic Error

Definition Code cannot be compiled and The program functions abnormally or


executed because it breaks the rules of produces wrong results because of
the programming language incorrect logical flow

Examples ➢ Missing colons ➢ Wrong sequences


➢ Misspelled keywords ➢ Errors in control structure of
➢ Capitalization errors conditional statement
➢ Missing indents or brackets

IDE can usually help us detect syntax errors and indicate them by error messages. However, we must
test the logical flow of our program repeatedly in order to correct logic errors.

22

You might also like