Python booklet-Grade VI
Python booklet-Grade VI
VI-VIII
Page 1 of 33
VI
Page 2 of 33
Introduction to Artificial Intelligence (AI)
Artificial Intelligence (AI) is a field of computer science that focuses on creating intelligent
machines capable of performing tasks that typically require human intelligence. AI involves
designing computer systems and programs that can learn, reason, and make decisions like
humans do.
AI can be explained as the development of computer programs or machines that can think and
learn from experiences, similar to how humans do. It involves teaching computers to perform
tasks that would typically require human intelligence, such as understanding and responding to
spoken language, recognizing objects in images, or playing games.
AI can be found in various technologies and applications we encounter in our daily lives. For
example, voice assistants like Siri or Alexa use AI to understand and respond to our spoken
commands, while recommendation systems on streaming platforms or online stores use AI to
suggest content or products based on our preferences.
In summary, AI is about creating intelligent machines that can mimic human intelligence and
perform tasks that usually require human thinking, learning, and decision-making abilities. It is
an exciting field that is shaping the future of technology and impacting various aspects of our
lives.
1. Voice Assistants: AI-powered voice assistants like Siri, Alexa, and Google Assistant are
commonly found in smart phones, smart speakers, and other devices. They can understand
spoken commands and perform various tasks such as answering questions, setting reminders,
playing music, and providing weather updates.
2. Online Recommendations: When you shop online or watch videos on platforms like
Amazon, Netflix, or YouTube, you may have noticed personalized recommendations. These
recommendations are based on AI algorithms that analyze your browsing or viewing history,
preferences, and similar user data to suggest products or content that you might be interested in.
Page 3 of 33
3. Social Media Algorithms: Social media platforms like Facebook, Instagram, and TikTok
utilize AI algorithms to curate your news feed or suggest posts and accounts to follow. These
algorithms consider factors such as your interests, engagement history, and interactions to show
you relevant content.
4. Virtual Assistants: Some chat bots or virtual assistants that you interact with on websites or
messaging apps use AI to understand and respond to your queries. These AI-powered assistants
can provide customer support, answer frequently asked questions, and assist with basic tasks.
5. Smart Home Devices: AI is integrated into many smart home devices, such as smart
thermostats, security systems, and lighting controls. These devices can learn your preferences,
adjust settings automatically, and provide energy-efficient solutions by analyzing data and
patterns.
These are just a few examples of how AI is present in our daily lives. It's important to note that
AI is continuously evolving and being integrated into various technologies and applications,
making our lives more convenient and efficient.
Python comes with pre-built libraries such as NumPy. To perform scientific calculations and
Python is used for human to computer interactions through chat bots. Chat bots use AI. Python
creates intelligent systems, explores machine learning algorithms.
Download and install Python Jupyter interpreter and PyCharm and get the most useful
package in machine learning in python. Understand its syntax using data visualization.
If you are a machine learning beginner and looking to finally get started using Python.
Page 5 of 33
Getting Started with Python Programming
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.
Page 6 of 33
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-oriented way or a functional way.
Page 7 of 33
Python comments
Comments can be used to explain Python code.
Comments can be used to make the code more readable.
Comments can be used to prevent execution when testing code.
Comments: Comments are used to explain and document your code. They are not executed by
the computer but provide information for human readers.
Example
#This is a comment
print("Hello, World!")
Comments can be placed at the end of a line, and Python will ignore the rest of the line:
Example
A comment does not have to be text that explains the code, it can also be used to prevent Python
from executing code:
Example
#print("Hello, World!")
print("Cheers, Mate!")
Variables: Variables are used to store and manipulate data in Python. You can think of
variables as containers that hold values. To create a variable, you give it a name and assign a
value to it using the assignment operator (=).
Example:
x = 10
y = "Hello"
Data Types: Python supports different data types, such as numbers, strings, and booleans.
Numbers can be integers (whole numbers) or floating-point numbers (numbers with decimal
points). Strings are sequences of characters enclosed in quotation marks. Booleans represent
either True or False.
Example:
x=5 # Integer
y = 3.14 # Floating-point number
name = "John" # String
is_student = True # Boolean
Page 9 of 33
Basics of Python syntax and structure
In Python, a program is made up of statements. Each statement is written on a separate line.
Unlike other programming languages, Python uses indentation (spaces or tabs) to group
statements together. Indentation helps Python understand the structure of your code.
Example 1: Print if value is a positive number
print("Hello, world!")
x=5
if x > 0:
print("Positive number")
Example 2: Check number and print if value is positive or negative
x = -2
if x > 0:
print("Positive number")
else:
print("Negative number")
Example 1( Addition of two numbers )
X = 5+3 # Addition
Print (“5+3 =”, x)
5+3=8
Flowchart
Page 10 of 33
Algorithm
Step1: Start
Step 2: Read 5, 3
Step 3: x=5+3
Step 4: Print x
Step 5: End
y = 10 - 2 # Subtraction
print("10 - 2 = ",y)
10 - 2 = 8
Flow Chart
Algorithm
Step1: Start
Step 2: Read 10, 2
Step 3: y=10-2
Step 4: Print y
Step 5: End
Page 11 of 33
Example 3 (Comparison)
x=5+3
y = 10 - 1
is_greater = x > y # Comparison
print("Is x is greater than y: ", is_greater)
Is x is greater than y: False
Algorithm
1. Assign 5 + 3 to x // Addition
2. Assign 10 - 1 to y // Subtraction
3. Assign the result of x > y to is_greater // Comparison
4. Print "Is x is greater than y: " concatenated with the value of is_greater
Page 12 of 33
Example 4 (Logical)
is_true = False and True # Logical
print(is_true)
False
Algorithm
1. Assign the result of False and True to is_true // Logical
2. Print the value of is_true
Page 13 of 33