Python booklet VII
Python booklet VII
VI-VIII
Page 1 of 33
VII
Page 14 of 33
What is a Programming Language?
Programming languages define and compile a set of instructions for the CPU (Central Processing
Unit) for performing any specific task. Every programming language has a set of keywords
along with syntax- that it uses for creating instructions.
Till now, thousands of programming languages have come into form. All of them have their own
specific purposes. All of these languages have a variation in terms of the level of abstraction
that they all provide from the hardware. A few of these languages provide less or no abstraction
at all, while the others provide a very high abstraction. On the basis of this level of abstraction,
there are two types of programming languages:
Low-level language
High-level language
The primary difference between low and high-level languages is that any programmer can
understand, compile, and interpret a high-level language feasibly as compared to the machine.
The machines, on the other hand, are capable of understanding the low-level language more
feasibly compared to human beings.
High-level languages use command words and Syntax which reflects everyday language, which
makes them easier to learn and use. High-level languages also offer the programmer
development tools such as libraries and built-in functions.
Examples of high-level programming languages in active use today include Python, JavaScript,
Visual Basic, Delphi, Perl, PHP, C#, Java and many others.
Page 15 of 33
They always require assemblers for translating instructions.
Low-level languages do not have a very wide application in today’s times.
Introduction to Python
In this introduction to programming using Python, we will explore various Real-World examples
to understand the basics of programming concepts. Students in grades 6 to 8 can better grasp the
fundamental ideas behind programming and its relevance in everyday life by relating
programming concepts to practical examples.
Variables:
What are Variables and Data types?
Variables, and data types, are fundamental concepts in Python. Variables are used to store data
values in memory for later use. Let's define each of these concepts
myvar = "John"
my_var = "John"
_my_var = "John"
myVar = "John"
MYVAR = "John"
myvar2 = "John"
2myvar = "John"
my-var = "John"
my var = "John"
Page 16 of 33
Data Types:
The data type is a classification that tells the computer what kind of data is being stored or used
in a program, such as numbers, text, or true/false values.
Real-World Examples: Consider a school library. Different types of books are stored on
different shelves. In programming, data types are like different categories of information that we
can store and manipulate. Here are some common data types in Python:
Operators
Python language offers numerous operators to manipulate and process data. Following is the list
of some basic operator types. Here, we will discuss only two types of operators.
Assignment Operator
Arithmetic Operators
Logical Operators
Relational Operators
Assignment Operator
Assignment operator is used to assign a value to a variable, or assign value of variable to another
variable.
Equal sign (=) is used as assignment operator in Python. Consider the following example
Example:
sum = 5
Value 5 is assigned to a variable named sum after executing this line of code.
Page 17 of 33
Arithmetic Operators
Arithmetic operators are used to perform arithmetic operations on data. Following table
represents arithmetic operators with their description.
Arithmetic Table
Page 18 of 33
Page 19 of 33
Python Program to Convert Kilometers to Miles
Page 20 of 33
Calculate Area of a triangle
Page 21 of 33
Python Program to Convert Celsius to Fahrenheit
Page 22 of 33
Python Program to check if a Number is Positive, Negative or 0
A number is positive if it is greater than zero. We check this in the expression of if. If it is False,
the number will either be zero or negative. This is also tested in subsequent expression.
Page 23 of 33
Python Program to check if a Number is odd or even
A number is even if it is perfectly divisible by 2. When the number is divided by 2, we use the
remainder operator % to compute the remainder. If the remainder is not zero, the number is odd.
Page 24 of 33