Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Python booklet VII

The document provides an overview of programming languages, distinguishing between low-level and high-level languages, with a focus on high-level languages like Python. It explains fundamental concepts such as variables, data types, and operators in Python, along with rules for naming variables and real-world examples to illustrate these concepts. Additionally, it includes basic Python programming examples for practical understanding.

Uploaded by

Aliya Raza
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python booklet VII

The document provides an overview of programming languages, distinguishing between low-level and high-level languages, with a focus on high-level languages like Python. It explains fundamental concepts such as variables, data types, and operators in Python, along with rules for naming variables and real-world examples to illustrate these concepts. Additionally, it includes basic Python programming examples for practical understanding.

Uploaded by

Aliya Raza
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Grade

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.

What are High-Level Languages?


High-level languages are programming languages that are designed to allow humans to write
computer programs and interact with a computer system without having to have specific
knowledge of the processor or hardware that the program will run on.

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.

They are very widely used and popular in today’s times.

Examples of high-level programming languages in active use today include Python, JavaScript,
Visual Basic, Delphi, Perl, PHP, C#, Java and many others.

What are Low-Level Languages?


Low-Level language is the only language which can be understood by the computer. Low-level
language is also known as Machine Language. The machine language contains only two symbols
1 & 0. All the instructions of machine language are written in the form of binary numbers 1's &
0's.

 They are also called machine-level languages.


 Machines can easily understand it.
 They are not very easy to understand.
 These languages depend on machines. Thus, one can run it on various platforms.

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

Rules for naming variables


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 variable name must start with a letter or the underscore character


 A variable name cannot start with a number
 A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9,
and _ )
 Variable names are case-sensitive (age, Age and AGE are three different variables)
 A variable name cannot be any of the Python keywords.

 Legal variable names:

 myvar = "John"
my_var = "John"
_my_var = "John"
myVar = "John"
MYVAR = "John"
myvar2 = "John"

 Illegal variable names:

 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:

a. Numeric Data Type:


- Real-World Examples: Think of a shopping receipt that lists the total amount spent. In
programming, numeric data types (e.g., integers and floating-point numbers) represent numerical
values. They can be used for calculations, keeping track of quantities, and representing
measurements.

b. String Data Type:


- Real-World Examples: Imagine you have a collection of student names in your class. In
programming, string data type is used to represent text or a sequence of characters. It can store
names, addresses, messages, and any other textual information.

c. Boolean Data Type:


- Real-World Examples: Consider a locked door. It can either be open or closed. A boolean data
type in programming represents two values: True or False. It is often used for conditions and
making decisions in programs.

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

Operator Name Description


It is used to divide the value on the left
/ Division Operator
side by the value on right side
* Multiplication Operator It is used to multiply two values

+ Addition Operator It is used to add two values


It is used to subtract the value on right
- Subtraction Operator
side from the value on the left side
It gives remainder value after dividing
% Modulus Operator
the left operand by right operand

Python Program to Add Two Numbers

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

You might also like