Introduction to Python Programming
Introduction to Python Programming
Grade 8
INTRODUCTION
1.Open source, versatile, easy to read, learn and write general purpose
programming language
2.User-friendly data structures
3.High-level language with simple syntax
4.Object-oriented language
5. Platform independent, Portable across Operating Systems and Interactive
6.It’s an Interpreted language. [Interpreted language is a programming
language in which programs are 'indirectly' executed ("interpreted") by an
interpreter program. This can be contrasted with a compiled language which
is converted into machine code and then 'directly' executed by the host CPU.]
7.Ideal for prototypes – provide more functionality with less coding
APPLICATIONS
Build a website
Develop games
Program robots
Perform scientific computations
Develop AI applications
Enterprise and Business applications
ORGANIZATIONS USING PYTHON
To evaluate an arithmetic
expression, it is not necessary to
use print() function. We can type
th expression, and the
interpreter (which acts as a
simple calculator) automatically
evaluates and shows the results.
PYTHON KEYWORDS AND
IDENTIFIERS
In this part of the lesson you will learn about keywords (reserved words in Python) and identifiers
(names given to variables, functions, etc.).
PYTHON KEYWORDS
Rules for
writing
identifiers
EXAMPLE
EXAMPLE
VARIABLES IN PYTHON
You need to store for your future also, what will you require? Well you need a contain er to store the food.
Similarly, when you are working with the values in Python, you require some storage to hold values for later
use. Such storage locations are known as variables.
DEFINITION OF VARIABLE
Employee code
10code
A.B.C LTD.
else
Student_blood_grp
ASSIGNMENT-2: EXECUTE THE FOLLOWING CODE AND MENTION THE OUTPUT
print(b)
print(c)
DATA TYPES-LET’S UNDERSTAND THE
CONCEPT
Suppose, you have planned a holiday trip during vacations, and you have to book
tickets for your family members. The first action that you need to take is to fill a
form to get the reservation done, where you need to give your required details
like your name, date of journey, name , age etc. Here every piece of data that you
enter is of a specific type, as your name is a String type, age is a numeric type and
date of journey is of date type. Similarly, in Python, one must specify in a
program, what kind of values will be stored in a specific variable.
While writing a Python program, you need to work on different types of data. F;or
example, if you have to enter the height of a person, you will be required to use
decimal value, but if you have to write the address of the person, then you need to
use a string or a collection of alphanumeric characters.
DATA TYPES -DEFINITION
The type of data value that can be stored in an identifier, such as a variable, is
known as its data type. The data type of a value or variable is an attribute that tells
what kind of data a variable can have.
Data types help in classifying different types of data values used in a program.
Python has standard data types that are use to define operations performed on
them.
MAIN DATA TYPES USED IN PYTHON
Sr. no. Data types Explanation
1. Integer (int) Represents integral /whole numbers (positive or negative)
2. Float (float) Represents floating points value; numbers with fractional part. The fractional
part of a floating point number may be 0 as well. Ex: 3.14, -48.6, 18.0 etc.
3. String (str) Represents strings of characters enclosed within quotation marks (‘ ‘ or “ “)
Example- ‘Hello’, “Employee_code”,’218’, etc.
TYPE() FUNCTION
If you want to know what type of data you are working with, use the type()
function. It is use to return the data type of a value.
INPUT() FUNCTION
Comments are the statements that are added to a program wih the purpose of
making the code easier to understand.
Compilers and interpreters generally ignore comments during the execution of
the program.
Comments are optional, they are needed from the user’s perspective.
TYPES OF COMMENT
Note: after the if condition there is a colon (:) and the condition body starts with an indentation of tab space. It is mandatory in Python
to indent the statements in the condition body else it will display an error.
Leading white space (spaces and taps) at the beginning of each statement, which is used to determine the group of statement, is
known as “indentation”.
example
What will happen if you enter a number grater than 200? No output will be displayed because no
statement is given to be followed if the given condition is false.
If-else statement
• The if-else control structure is used when either of the two different actions is to be performed depending upon
the result of the conditional expression.
• It contains two blocks of statements. In case the conditional expression evaluates to true, the statements in the
‘if’ block are executed, and if the result is false, then the statement in the ‘else’ block get executed.
• For example, you can go out to play if it doen’t rain else you have to play indoor games.
• Syntax:
if<condition>:
Statement 1
else:
Statement 2
example
Assignment 5
Write a program to check the grade of a student using if-elif statement. The system should ask the
marks from the student. As soon as he/she enters the marks, the system should display grade based on
marks. Program:
Marks Grade
name=input("Enter your name:-")
Marks greater than equal to A marks=float(input("Enter your marks:-"))
75
Marks greater than equal to B if marks>=75:
60
Marks less than 60 C print("Your grade is 'A'.")
elif marks>=60:
print("Your grade is 'B'.")
else:
print("Your grade is 'C'.")
print("Congratulations for your grade! ")
If-elif-else statement
• Sometimes we need to work with multiple conditions. In this case, only using if-else construct doesn't
serve the purpose. The if..elif..else statements provide a compact way to perform multiple tests on a
condition.
• For example, when you visit a bank, you go to the counter according to the service you want to avail. If
you want to deposit cash, you go to counter 1, if want to enquire about the cheque, you go to counter 2
etc.
• Syntax:
if<condition 1>:
Statement 1
elif<condition 2>:
Statement2
else:
Statement 3