1
Installation:
Software: Python: [Link]
Click on download python 3.13.1 Once its download click on setup
Now Pycharm [Link]
scroll down and download Pycharm community edition
2
Once setup is download click on set up
3
Introduction to Python
Python is a simple Programming language that is used to write codes for the computer programs.
Python was created by Guido Van Rossum when he was working at Centrum Wiskunde &
Informatica (CWI), which is a National Research Institute for Mathematics and Computer Science in
Netherlands. The language was released in 1991.
Python is a high-level programming language.
Some of the features that make Python so popular are as follows:
❖ It is an easy to learn general-purpose programming language.
❖ It has a simple syntax.
❖ Python is a case sensitive language.
❖ It is an interpreted language.
❖ It is free to use and even free for commercial products.
APPLICATIONS OF PYTHON PROGRAMMING
Python is a popular and easy to learn language.
It can be used to:
❖ Build a website
❖ Develop games
❖ Program robots
❖ Perform scientific computations
❖ Develop artificial intelligence applications
Using comment in python
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 starts with a #, and Python will ignore them:
Using print() function
The print() function is used to display the output of any command on the screen. It can also be
used to print the specified messages.
Python is a case-sensitive programing language. It means that Python differentiates between
capital and small letters. For example, Print (P capital) and print (p small) are two different
things for Python, where print is a valid command in Python, while Print is just a word and
not a command.
4
You can also pass more than one argument to the print() function. In such a case, the arguments
are separated by commas.
Exercise:
a) Write a program to print general details about your school in five lines.
b) Create a program that prints your name and age, using two separate print statements.
Variables:
Variables are containers for storing data values.
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.
Variable Names
A variable can have a short name (like x and y) or a more descriptive name (age, carname,
total_volume).
Rules for Python variables:
a) A variable name must start with a letter or the underscore character
b) A variable name cannot start with a number
c) A Python keyword cannot be used as a variable name.
d) A variable name can only contain alpha-numeric characters and
Underscores (A-z, 0-9, and _)
e) Variable names are case-sensitive
(age, Age and AGE are three different variables)
5
Values are assigned to variables using assignment operator (=). For example, the statement x=25
assigns the value 25 to the variable x.
Observe the following codes to understand the use of assignment operators:
a=10 #Value 10 is assigned to the variable a
b=20 #Value 20 is assigned to the variable b
c=a+b #The numbers are added and the value is assigned to the variable c, i.e.,
30 is assigned to the variable c.
For example:
Exercise:
a) Create a variable called age and set its value to 10. Print the value of age.
b) Create two variables, x and y, and assign the values 5 and 8 to them, respectively. Add
the values of x and y together and print the result.
6
Using input() function
The input() function allows user input. Input() function is used to accept the value for a variable
from the user. To input integer and float values, we can use int or float along with input().
For example:
Exercise:
Write a program that asks for two numbers and prints their product.
7
More to know:
To combine both text and a variable, Python uses the + character:
For example:
Exercise:
a) Write a program that asks the user to enter two numbers and prints the sum of these two numbers.
b) Write a program that asks the user for the length of one side of a square and prints the area of the
square.
Formula
Area = side × side
8
DATA TYPES:
Every value has a datatype, and variables can hold values. Python Data Types are used to define
the type of a variable. Data types are the classification or categorization of data items. It
represents the kind of value that tells what operations can be performed on a particular data.
Here are some data types commonly used in python programming.
Python
Name Keyword Description
string str a sequence of characters that can be indexed
integer int a whole positive or negative number
float float a positive or negative number with a decimal
complex complex represented by a real and imaginary number component
boolean bool can be of value True or False
list list a sequence of elements that can be indexed
tuple tuple a sequence of elements that can be indexed and is immutable
a collection of elements that is unordered and doesn't contain
set set duplicates
dictionary dict a collection of elements each comprised of a key-value pair
How to declare the data type:
9
Here in grade 6 we will be dealing with few data types.
Data Types Classes Description
Numeric int, float, complex holds numeric values
String str holds sequence of characters
• Integers – This value is represented by int class. It contains positive or negative whole numbers
(without fractions or decimals). In Python, there is no limit to how long an integer value can be.
• Float – This value is represented by the float class. It is a real number with a floating-point
representation. It is specified by a decimal point.
• Complex Numbers – A complex number is represented by a complex class. It is specified as (real
part) + (imaginary part) j. For example – 2+3j
For example:
10
String
The sequence of characters in the quotation marks can be used to describe the string. A string can be
defined in Python using single, double, or triple quotes.
String dealing with Python is a direct undertaking since Python gives worked-in capabilities and
administrators to perform tasks in the string.
When dealing with strings, the operation "hello"+" python" returns "hello python," and the operator + is
used to combine two strings know as string concatenation
For example:
Exercise:
a) Create a variable with integer value, float value, complex value.
b) Write a program that takes two strings first and last name as input from the user and
concatenates them.
Arithmetic Operators in Python
Python arithmetic operators are used to perform mathematical operations such as addition, subtraction,
multiplication, division, and more on numbers. Arithmetic operators are binary operators in the sense
they operate on two operands. Python fully supports mixed arithmetic. That is, the two operands can be
of two different number types. In such a situation.
Operator Operation Example
+ Addition 5+2=7
- Subtraction 4-2=2
* Multiplication 2*3=6
/ Division 4/2=2
11
// Floor Division 10 // 3 = 3
% Modulo 5%2=1
** Power 4 ** 2 = 16
Operator precedence:
When a calculation has multiple operators, each operator is evaluated in order of precedence. Ex: 1 + 2 * 3 is 7
because multiplication takes precedence over addition. However, (1 + 2) * 3 is 9 because parentheses take
precedence over multiplication.
For example:
12
Exercise:
a) Write a Python program to find the average of three numbers.
b) Write a Python program to convert minutes to seconds.
Common types of errors:
Different types of errors may occur when running Python programs. When an error occurs, knowing the type of
error gives insight about how to correct the error. The following table shows examples of mistakes that anyone
could make when programming.
13
14
WORKSHEET
Find the error in the following code and write the correct code in the given boxes.
1. print(“hamza')
2. Print(5+8)
3. print{A*3}
4. print “Raj”
5. print[-20+30]
Write a python program having the length of a rectangle L=12 and width W=8, calculate the perimeter.
Formula: P=2×(Length+Width)
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
Write a python program having the length of a rectangle L=10 and width W=5, find the area.
Formula: A=Length×Width
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
15
Write a Python program that performs the following operations:
• Adds two numbers
• Subtracts two numbers
• Multiplies two numbers
• Divides two numbers
Example:
• Given numbers: 8 and 4
• Perform all the operations and display the results.
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
16
Search the correct word from crossword and fill in the blanks.
1. ________________________________ is known as reserve word.
2. ________________________________ has decimal value.
3. ________________________________ has no decimal value.
4. ________________________________ is used to store data.
17