You are on page 1of 54

Pag e|

GOVT. POLYTECHNIC
HAMIRPUR
INDUSTRY TRAINING REPORT
ON
PYTHON PROGRAMMING.
FROM

SUBMITTED TO GOVT. POLYTECHNIC HAMIRPUR

IN PARTIAL FULFILLMENT OF THE DIPLOMA OF

COMPUTER ENGG.

SESSION: AUG-DEC 2023


SUBMITTED BY –

ANISH

MALHOTRA

(2207302040

02)
Pag e|
2

Acknowledgement
It is my pleasure to be indebted to various people, who

directly or indirectly contributed in the development of

this work and who influenced our thinking, behavior and

act during the course of study.

We are heartily thankful to Excellence Technology


MOHALI FROM
G.P.H for letting us choose such an interesting field for our

industrial Training andfor their support in all the problems

faced by during the


project.

Lastly, we would like to thank the almighty and our

parents for their moral support and friends with whom

we shared our day to day experience and received loots

of suggestion that improved our quality of daily work.


Pag e|
3
TRAINING CERTIFICATE
Pag e|
4

DAILY DIARY
Pag e|

TRAINING
5

OBJECTIVE
To get exposed to the training

environment. To have a basic

understanding of the culture , work ethics

and trade related work practices at the

organization.

To have an opportunity to observe the

processes, procedures and standards that

the industry uses to ensure quality,

productivity and economy of the products or

services that it undertakes and get a

firsthand experience to work within the

industry.

To relate my current level of

knowledge with the industrial experience in

the form of generating reports on the basis


Pag e|
6
of observation and generates a model of its

operations or processes or work flow.


Pag e|
7

Contents.
1. WHAT IS PYTHON ?

2. PYTHON VARIABLE AND


DATA TYPES ?
3. PYTHON OPERATORS ?

4. CONTROL FLOW
STATEMENTS ?
5. LOOPS IN PYTHON ?

6. FUNCTIONS IN PYTHON ?

7. FINAL PROJECT.
Pag e|
8

INTRODUCTION OF PYTHON

Designed by: Guido van Rossum

Python (programming language)

Multi-paradigm: object-oriented, procedural


Paradigm
(imperative), functional, structured, reflective
Designed by Guido van Rossum.
Developer Python Software Foundation
First
20 February 1991
appeared
Python: It is a high-level, general-purpose programming
language. Its design philosophy emphasizes code readability with
the use of significant indentation. Python is dynamically-typed and
garbage-collected. It supports multiple programming paradigms,
Pag e|
including structured, object-oriented and functional 9
programming.
Pag e|
10

PYTHON VARIABLE AND DATA TYPES :

1 Variable can hold value and every value has a data type -
a. We do not need the define the type of the variable
while declaring.
b. Example:- a=5
2. The variable a hold the integer value 5.
3. User can not define any Data Type.
4. Python interpreter will automatically variable a given integer
Data Type.
a. Python provide the type () function to check the data
type any variable.

PYTHON AND DATA TYPES ON VARIABLE:

1. Variable naming rules

2. Declaring variables

3. Multiple Assignment

4. Deleting variables

5. Python Variable Types


Pag e|
11

Variable naming rules

1.The first character of variable must be an alphabet or


underscore(_) .

2.All the character except the first character may be

an alphabet of lower case like(a-z), upper case like(A-

Z) and they use the digits (0-9).

3.Identifier name must not use any white space and

special character (!,@,#,%).

4.Identifier name must not be similar any keyword.

5.Identifier name are case sensitive for example:- NAME

and name are the different name not a same variable.

6.Example of valid identifier name is :- _a,a123 etc

Declaring variables
1. Python does not bind us to declare a variable

before using the validation.


Pag e|
12
2. It allows to create a variable at the required time.

3. We don’t need to declare explicitly variable.

4. We assign any value to the variable that variable declared.

5. The equal (=) operator is used to assign the value of


variable.

6. Example :- A=10

A is a variable name and (=) use the assign the value

and 10 is a value of A.
Pag e|
13

Multiple Assignment :-

 Python allows us to assign a value to multiple

variables in a singlestatement.

 It is known as Multiple Assignment.


 We can apply multiple assignment in two ways.

 Either by assigning a single value to multiple

variables or assigning amultiple value in multiple

variables.

Assigning multiple values to multiple variables-

Example:-

a,b,c=10,20,30
Pag e|
14
print(

a)

print(

b)

print(

c)

User assign the multiple variables and assign the

multiple value And second step print the all

values.
Pag e|
15

Deleting variables :-

We can delete the variable use Del

keyword syntax:-

del<variable_name

> Example :-

x=5

print(x)

del x

print(x)

I print the variable x and assign the value

and print the value after printing the value

Delete the variable x.

Python variables:-

Example of python
Pag e|
16
variable:- First Declare

variable Second add

next variable

Finally print the variable

values A=10

B=10
Pag e|
17

C=A+B

Print(c)

Python variable types:-

They are the two types of variables in Python:-

First one is Local Variable.


Second one is Global variable.

Local variable :-

 The local variable is created under the function is

not define the outside of the function. It is known as

local variable and local scope.

 Local Variable Example :-

def

sample():

y=“local”

print(y)
Pag e|
18
sample
()

Global variable :-

 In python variable declare outside of the

function in global scope is known as global variable.

This means that a global variable can accessed

inside or outside of the function.

Example of Global Variable :-


x=“global”
Pag e|
19

def sample():
print(“x inside :-

” ,x sample()

print(“x outside:-”,x)

Python data types :-

1.Variable can hold value and every value has a data


type.
2.We do not need the define the type of the

variable while declaring.

Example:- a=5
3.The variable a hold the integer value five.
4.User can not define any Data Type.
5.Python interpreter will automatically

variable a given integer Data Type.

6. Python provide the type () function to


check the data type any variable.
Pag e|
20
EXAMPLE OF CHECK THE DIFFERENT DATA TYPES:-
a=10
b=“Hi Python”

c=10.5
Print(type(a))
Pag e|
21

Print(type

(b))

Print(type

(c))

Python data types


chart
Pag e|
22

Python Operators
 The operator can be defined as a symbol which

is responsible fora particular operation between two

operands.

 Operators are the pillars of a program on which


Pag e|
23
the logic is built in a specific programming language.

Types of python operators:-


Pag e|
24

1.Arithmetic operators
2.Comparison operators
3.Assignment Operators
4.Logical Operators
5.Bitwise Operators
6.Membership Operators
7.Identity Operator

Control flow statements :-


The control flow statements are divided

into three parts:-


Pag e|
25
Conditional statements
Iterative statements
Pag e|
26

Transfer statements
Pag e|
27

Conditional statements :-
 The conditional statements are depending on

whether a givencondition is true or false.

 You can execute different blocks of codes

depending on theoutcome of a condition.

 Condition statements always evaluate to

either true or falseTypes of conditional

statements:-

1.if statements
2.If-else
3.If-elif-else
4.Nested if-else

if statements :-
In control statement the if statement is the

simplest form.it takes a condition and evaluate

to either True or False

If the condition is true then the true block of


Pag e|
28
code will be executed and if condition is false then

the block of code is skipped and controller moves

the next block of code like else block.

Syntax of if

statement:- If

condition:

statement 1
statemen

t2

statemen

tn
Pag e|
29

If-else statement :-

Example of if else statement:-

num=5 if num >=0:

print(“number is positive”)
else:
print(“number is negative”)

If-elif-else :-
If-elif-else condition statement has an elif

blocks to chainmultiple conditions one after


Pag e|
30
another.

This is useful when you need to check multiple
coditions.
The if, elif, else we can make a tricky decision.
The elif statement checks multiple

conditions one by on
eand if the condition fulfills

then execute the code.


Pag e|
31

Flow chart of if elif else:-

Example of if elif else statement:-

num=3
If num >0:
print(“positive”)
Pag e|
32
elif num==0:
print(“zero”)
else:
print(“negative number”)
Pag e|
33

Nested if else statement :-


 Nested if else statement:-in

python nested if elsestatement is an if

statement inside the if else statement.

 It is allowed in python to put

any number ofif statement in

another if statement.

 Indentation is the only way to different level


nesting.
 We can have a if …elif …else statement

inside anotherif elif ..else statement this is

called nesting in computer.

 Any number of these statement can

be nested insideone another.

Syntax of the nested-

if else: If condition
Pag e|
34
outside:

if condition inside:

statement of

inside if
else:
statement of inside else:
statement of

outside if else:

outside else
Statement outside if block
Pag e|
35

Flow chart of Nested if else statement :-


Pag e|
36

Example of nested if else statement:-

a=int(input(“Enter 1st

value:-”)

b=int(input(“Enter 2st

value:-”) If a>=b:
if a == b:
print(a ‘and’, b, ‘are equal’)
else:

print(a, ‘is greater then’, b)


else:
Print(a, ‘is smaller then’,b)
Pag e|
37

Transfer statements :-
Pag e|
38

Transfer statements alter the way a

logic gets executed. These statements are

often used in loops for and while. Let’s

have a look at the transfer statements

below.

Types of Transfer statements :-


1. Break
2.Continue
3.Pass

Break statement :-
 We can use the break statements

inside a while loopusing the same approach.

 If condition to stop the while loop.

If the current character is space then the


Pag e|
39
condition evaluates to true. Then the

break statement will execute and the

loop will terminate.

 Else loop will continue to work

until the main loopcondition is true.


Pag e|
40

Example of break statement:-


number= [10,20,30,40,50]

for i in number:

if i>40:

break

print(“current number”,i)

Continue statement :-
 The continue statement skips the current

iteration of a loop andimmediately jumps to the next

iteration.

 Use the continue statement when you want to

jump to the nextiteration of the loop immediately.

 The interpreter found the continue statement

inside the loopitskips the remaining code and

moves the next iteration.

 Example count the total number of ‘m’ in a string


 If statement checks the current character is m or
Pag e|
41
not .if it is notmit continues to the next iteration to

check the following letter.

Example of continue statement:-

numbers=[2,3,1

1,7] for I in

numbers:

print(“current number is “,i)


if i > 10:
continue
Pag e|
42

square=i * I
print(“square of a current number is “, square)

PASS STATEMENT :-
The pass statement is null statement.

Nothing happenswhen the statements Is

executed. It is used in empty functions or

classes. when the interpreter finds a pass

statements in the program it returns no

operation.

Syntax of pass

statements: for

elements in sequence:

if condition:

pass
Pag e|
43

Example of pass statements:-


num = [1,4,5,3,7,8]

for i in num:

pass
Pag e|
44

months=[“January”,”june”,”march”,”april”]

for Monday in

months: pass

print(months)

Functions
Every function starts with a “def” keyword.
Every function should have a unique name.
Every function name are not a same any
keyword.
User decide the parameters are given or not.
User decide the arguments are

given or not butparameters and


Pag e|
45
arguments are optional.

But the parameters and arguments are

given to the user,so user given the parameters

and arguments in parenthesis.

Every function name without arguments

should end witha(:).

Every function has to return any value

and return emptyvalue.

Multi value return can be done in (Tuple)


Pag e|
46

Types of functions :-
1. Built in function

2. User-defined Function

3. Function calling:-
So, function calling is a simple process.
So, call the function as a function name

so user create afunction add and user call the

function is “ABC”.

Otherwise interpreter shows the error.


So user call the function as a same name

not use differentname.

User given the arguments name and end

the program usercall the different arguments so

this situation interpreter given the error.

End of the part user define the

function and call the function are same


Pag e|
47
name arguments and parameters include

in the function are call the same name.

Simple example of call function :-

def add(a,b): # define function and add

parameters sum=a+b #third variable

add the value


Pag e|
48

return sum #use return statements

a=int(input(“enter 1st value:-”) #user

input values b=int(input(“enter 2nd

value:-”) # user input

values c=add(a,b) #call function


Print(“the result is :-”,c) # print value

Built in function:-
The functions which are come along with

python itself are called a built in function

or predefined function.

Built in function are like:- range(), id() ,

type(), input() etc

Example:-python range function


Pag e|
49
generates the immutable sequence of

numbers starting from the given start

integer to the stop integer.

User-defined function:-
Functions which are created by

programmer according to the requirement

are called a user defined function.


Pag e|
50

Example of simple create function:-

def sample():

x=10

print(

x)

sample()
Pag e|
51

Tkinter

Python offers multiple options for developing GUI


(Graphical User Interface)

Python with tkinter is the fastest and easiest way to


create the GUI applications. Creating a GUI using
tkinter is an easy task
Pag e|
52

Project given by the trainer

• from tkinter import *

• master = Tk()

• Label(master, text='First
Name').grid(row=0)

• Label(master, text='Last
Name').grid(row=1)

• e1 = Entry(master)

• e2 = Entry(master)

• e1.grid(row=0, column=1)
Pag e|
53

• e2.grid(row=1, column=1)

• mainloop()
Pag e|
54

THANK
YOU

You might also like