0% found this document useful (0 votes)
18 views11 pages

Practical 06

This is Ai lab manual part 6
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)
18 views11 pages

Practical 06

This is Ai lab manual part 6
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/ 11

Department of: Subject of:

Information Technology Artificial Intelligence

Quaid-e-Awam University of Year 4TH Semester 8TH


Engineering, Sciences & Technology
Batch 19IT Duration 03
Hours
Nawabshah

PRACTICAL 06
TO PRACTICE THE SHELL SCRIPTING IN PYTHON

----------------------------------------------------------
OBJECTIVES
• Introduction to Artificial Intelligence Applications
• Introduction to python programming
• 1st Python program
• Python variables
• Python operators
• Python collections

REQUIREMENTS
• PC with windows
• Anaconda environment/Online python compiler
6.1 AI APPLICATIONS

• Gaming: AI plays crucial role in strategic games such as chess, poker, tic-
tactoe, etc., where machine can think of large number of possible positions
based on heuristic knowledge.

• Natural Language Processing: It is possible to interact with the computer that


understands natural language spoken by humans.

• Expert Systems: There are some applications which integrate machine,


software, and special information to impart reasoning and advising. They
provide explanation and advice to the users.

• Vision Systems: These systems understand, interpret, and comprehend visual


input on the computer. For example,
✓ A spying aero plane takes photographs, which are used to figure out
spatial information or map of the areas.
✓ Doctors use clinical expert system to diagnose the patient.
✓ Police use computer software that can recognize the face of
criminal with the stored portrait made by forensic artist.

• Speech Recognition: Some intelligent systems are capable of hearing and


comprehending the language in terms of sentences and their meanings while
a human talks to it. It can handle different accents, slang words, noise in the
background, change in human’s noise due to cold, etc.

• Handwriting Recognition: The handwriting recognition software reads the


text written on paper by a pen or on screen by a stylus. It can recognize the
shapes of the letters and convert it into editable text.

• Intelligent Robots: Robots are able to perform the tasks given by a human.
They have sensors to detect physical data from the real world such as light,
heat, temperature, movement, sound, bump, and pressure. They have
efficient processors, multiple sensors and huge memory, to exhibit
intelligence. In addition, they are capable of learning from their mistakes and
they can adapt to the new environment.

6.2 INTRODUCTION TO PYTHON

6.2.1 What is Python?

• Python is a popular programming language. It was created by Guido van


Rossum, and released in 1991.
• It is used for:
✓ web development (server-side),
✓ software development, ✓ mathematics,
✓ System scripting.

6.2.2 What can Python do?

• Python can be used on a server to create web applications.


• Python can be used alongside software to create workflows.
• Python can connect to database systems. It can also read and modify files.
• Python can be used to handle big data and perform complex mathematics.
• Python can be used for rapid prototyping, or for production-ready software
development.

6.2.3 Why Python?

• Python works on different platforms (Windows, Mac, Linux, Raspberry


Pi, etc.).
• Python has a simple syntax similar to the English language.
• Python has syntax that allows developers to write programs with fewer lines
than some other programming languages.
• Python runs on an interpreter system, meaning that code can be executed
as soon as it is written. This means that prototyping can be very quick.
• Python can be treated in a procedural way, an object-orientated way or a
functional way.
6.3 Getting Started

Let's write our first Python file, called helloworld.py, which can be done in any text
editor.

6.3.1 Comments in Python


• Python has commenting capability for the purpose of in-code
documentation.
• Comments start with a # and python will render the rest of the line as a
comment.
6.3.2 Docstrings
• Python has also extended documentation capability, called docstrings.
• Docstrings can be one line or multiline.
• Doctrings starts with triple quotes “ “ “ at the start and end of the string to
make it multiline comment.

6.3.3 PYTHON VARIABLE


A Python variable is a reserved memory location to store values. In other words, a
variable in a python program gives data to the computer for processing.

6.3.4 PYTHON VARIABLE TYPES


Every value in Python has a datatype. Different data types in Python are Numbers,
List, Tuple, Strings, Dictionary, etc. Variables in Python can be declared by any
name or even alphabets like a, aa, abc, etc.

6.3.5 How to create python variables


Unlike other programming languages, Python has no command for declaring a
variable. A variable is created the moment you first assign a value to it. Variables
do not need to be declared with any particular type and can even change type
after they have been set.
6.3.6 Python String Concatenation and Variable
To combine both text and a variable, Python uses the + character:

6.3.7 Python Numbers


There are three numeric types in Python:
• int
• float
• Complex
To verify the type of any object in Python, use the type () function.
6.3.8 Python Casting
There may be times when you want to specify a type on to a variable. This can be
done with casting. Python is an object-orientated language, and as such it uses
classes to define data types, including its primitive types.Casting in python is
therefore done using constructor functions:
int() - constructs an integer number
float() - constructs a float number str()
- constructs a string

6.3.9 How to get input in python?


6.4 Python operators
Operators are used to perform operations on variables and values. Python
divides the operators in the following groups:
• Arithmetic operators
Arithmetic operators are used with numeric values to perform common
mathematical operations:
( +, -, *, /, %(mod), **(exp) , //(floor div))
• Assignment operators
Assignment operators are used to assign values to variables.
• Comparison operators
Comparison operators are used to compare two values: (
==, !=, >, <, >=, <=)
• Logical operators
Logical Operators in Python are used to perform logical operations on the
values of variables. The value is either true or false.
• Identity operators
Identity Operators in Python are used to compare the memory location of
two objects. The two identity operators used in Python are (is, is not).

✓ Operator is: It returns true if two variables point the same object and false
otherwise
✓ Operator is not: It returns false if two variables point the same object and
true otherwise
• Membership operators
Membership operators are used to test if a sequence is presented in an
object: in, not in
6.5 Python Collections
There are four collection data types in the Python programming language:
• List is a collection which is ordered and changeable. Allows duplicate
members. • Tuple is a collection which is ordered and unchangeable. Allows
duplicate members.
• Set is a collection which is unordered and unindexed. No duplicate
members. • Dictionary is a collection which is unordered, changeable and
indexed. No duplicate members.

6.5.1 How to create a Dictionary?

6.5.2 How to access items of dictionary?


We can access the items of a dictionary by referring to its key name, inside square
brackets:

6.5.3 Adding Items in dictionary


Adding an item to the dictionary is done by using a new index key and assigning a
value to it:
EXERCISE
1. What is an expression?

2. What is a syntax error?

3. What is the result of this expression: “*” * 10.

4. What is a variable?

5. What are the primitive built-in types in Python?

6. When should we use “”” (tripe quotes) to define strings?

7. Assuming (name = “John Smith”) what does name[1] return What

about name [-2]?

• What about name [1:-1]?

• How to get the length of name?

8. Create two variables of type int & float and caste into string.

9. Write a program to show whether the number is greater than, less than or

equal to the other number.

10. Write a program to show add, sub, mul & div between two variables.

You might also like