0% found this document useful (0 votes)
17 views23 pages

Manvi Report

Internship report

Uploaded by

vishvendra0912
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views23 pages

Manvi Report

Internship report

Uploaded by

vishvendra0912
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

A

INDUSTRIAL TRAINING

REPORT
Submitted by
ON
Vishvendra Singh
21EBKCS114
Python

Organization
(Udemy)
Submitted in partial fulfillment for the Degree

of

B.Tech

in

Computer Science

Session: 2022-23
CSE
DEPARTMENT OF COMPUTER SCIENCE
B.K. BIRLA INSTITUTE OF ENGINEERING &TECHNOLOGY
PILANI - 333 031 (RAJ)
(Affiliated to Bikaner Technical University, Kota)

1 | P a ge
ACKNOWLEDGEMENT

I have taken efforts in this project. However, it would not have been possible without the
kind support and help of many individuals and organizations. I would like to extend my
sincere thanks to all of them. I am highly indebted to Udemy for their guidance and
constant supervision as well as for providing necessary information regarding the course
& also for their support in completing the course.

3 | P a ge
TABLE OF CONTENT

CERTIFICATE ......................................................................................... 2

ACKNOWLEDGEMENT ........................................................................ 3

1. INTRODUCTION

1. What is Python ............................................................................. 5

2. History .......................................................................................... 5

3. Python Feature ............................................................................. 6

2. Operator .............................................................................................. 7

3. Data Structure In Python

1. List .............................................................................................. 11

2. Tuple ......................................................................................... 13

3. Dictionary .................................................................................. 15

4. Functions ......................................................................................... 17

5. Hands On With Python .................................................................... 19

6. Conclusion……………………………………………………………24

4 | P a ge
INTRODUCTION

1. PYTHON
Python is a high-level, interpreted, interactive and object-oriented scripting
language. Python is designed to be highly readable. It uses English keywords
frequently where as other languages use punctuation, and it has fewer syntactical
constructions than other languages.

• Python is Interpreted − Python is processed at runtime by the interpreter. You do


not need
to compile your program before executing it. This is similar to PERL and PHP.

• Python is Interactive − You can actually sit at a Python prompt and interact
with the
interpreter directly to write your programs.

• Python is Object-Oriented − Python supports Object-Oriented style or


technique of programming that encapsulates code within objects.

• Python is a Beginner's Language − Python is a great language for the


beginner-level programmers and supports the development of a wide range of
applications from simple text processing to WWW browsers to games.

2. History of Python
Python was developed by Guido van Rossum in the late eighties and early
nineties at the National Research Institute for Mathematics and Computer Science in
the Netherlands.

Python is derived from many other languages, including ABC, Modula-3, C, C++,
Algol-68, SmallTalk, and Unix shell and other scripting languages.

Python is copyrighted. Like Perl, Python source code is now available under the
GNU General Public License (GPL).

Python is now maintained by a core development team at the institute, although


Guido van Rossum still holds a vital role in directing its progress.

5 | P a ge
3. Python Features
Python's features include −

• Easy-to-learn − Python has few keywords, simple structure, and a clearly defined
syntax.

This allows the student to pick up the language quickly.

• Easy-to-read − Python code is more clearly defined and visible to the eyes.

• Easy-to-maintain − Python's source code is fairly easy-to-maintain.

• A broad standard library − Python's bulk of the library is very portable and cross-
platform

compatible on UNIX, Windows, and Macintosh.

• Interactive Mode − Python has support for an interactive mode which allows
interactive

testing and debugging of snippets of code.

• Portable − Python can run on a wide variety of hardware platforms and has the

same interface on all platforms.

• Extendable − You can add low-level modules to the Python interpreter. These
modules

enable programmers to add to or customize their tools to be more efficient.

• Databases − Python provides interfaces to all major commercial databases.

• Scalable − Python provides a better structure and support for large programs than
shell

scripting.

6 | P a ge
Python has a big list of good features
• It supports functional and structured programming methods as well as OOP.

• It can be used as a scripting language or can be compiled to byte-code for


building large applications.

• It provides very high-level dynamic data types and supports dynamic type checking.

• It supports automatic garbage collection.

• It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.

OPERATORS

7 | P a ge
Arithmetic operators: Python arithmetic operators are used to perform addition,
subtraction, multiplication, and division. They act as basic mathematical operations.

Example:

x = 15

y=4
print('x + y =', x + y)

# Output: x + y = 19

print ('x - y =', x-y)

# Output: x - y = 11

print('x * y =', x*y)

# Output: x * y = 60

Assignment operators: Assignment operators are used in Python to assign values to variables.

a = 5 is a simple assignment operator that assigns the value 5 on the right to the variable a on
the left.

There are various compound operators in Python like a += 5 that adds to the variable and later
assigns the same. It is equivalent to a = a + 5.
Comparison operators: Comparison operators are used to compare two values.

x = 10

y = 12

print('x > y is', x>y)

# Output: x > y is False

print('x < y is', x<y)

# Output: x < y is True

Logical operators: Comparison operators are used to compare values. It returns either True or
False according to the condition.

7|Page
Example:

x = True

y = False

print('x and y is', x and y)

#Output: x and y is False


print('x or y is', x or y)

#Output: x or y is True.

Identity operators: is and is not are the identity operators in Python. They are used to
check if two values (or variables) are located on the same part of the memory. Two variables
that are equal does not imply that they are identical.

x1 = 5

y1 = 5
print(x1 is not y1)

# Output: False

Membership Operators: in and not in are the membership operators in Python. They are
used to test whether a value or variable is found in a sequence (string, list, tuple, set and
dictionary).

In a dictionary we can only test for presence of key, not the value.

x = 'Hello world'

y = {1:'a',2:'b'}

print('H' in x)

# Output: True

print(1 in y)

# Output: True

Bitwise Operators: Bitwise operators act on operands as if they were strings of binary digits.
They operate bit by bit, hence the name.

For example, 2 is 10 in binary and 7 is 111.

8|Page
Ope rator Pre ce dence In Python

10 | P a g e
Data Structure In
Python

1. LIST
The list is a most versatile datatype available in Python which can be written as a list
of comma- separated values (items) between square brackets. Important thing about
a list is that items in a list need not be of the same type.

Creating a list is as simple as putting different comma-separated values between


square brackets. For example –

list1 = ['physics', 'chemistry', 1997, 2000]


list2 = [1, 2, 3, 4, 5 ]
list3 = ["a", "b", "c", "d"]

Basic List Operations

Lists respond to the + and * operators much like strings; they mean concatenation and
repetition here too, except that the result is a new list, not a string.

Python Expression Results Description

len([1, 2, 3]) 3 Length

[1, 2, 3] + [4, 5, 6] [1, 2, 3, 4, 5, 6] Concatenation

['Hi!'] * 4 ['Hi!', 'Hi!', 'Hi!', 'Hi!'] Repetition

3 in [1, 2, 3] True Membership

for x in [1, 2, 3]: print x, 123 Iteration

11 | P a g e
List Functions & Methods
Python includes the following list functions −

Sr.No. Functions & Methods with Description

1 len(list)

Gives the total length of the list.

2 max(list)

Returns item from the list with max value.

3 min(list)

Returns item from the list with min value.

4 list(seq)

Converts a tuple into list.

5 list.append(obj)

Appends object obj to list

6 list.insert(index, obj)

Inserts object obj into list at offset index

7 list.reverse()

Reverses objects of list in place

8 list.sort()

Sorts objects of list

9 list.remove(obj)

Removes object obj from list

11 | P a g e
2. TUPLES
A tuple is a collection of objects which ordered and immutable. Tuples are sequences, just like
lists. The differences between tuples and lists are, the tuples cannot be changed unlike lists and
tuples use parentheses, whereas lists use square brackets.
Creating a tuple is as simple as putting different comma-separated values. Optionally you can put
these comma-separated values between parentheses also. For example −
tup1 = ('physics', 'chemistry', 1997, 2000)
tup2 = (1, 2, 3, 4, 5 )
tup3 = "a", "b", "c", "d"
The empty tuple is written as two parentheses containing nothing −
tup1 = ( )
To write a tuple containing a single value you have to include a comma, even
though there is only one value −
tup1 = (50,)
Like string indices, tuple indices start at 0, and they can be sliced, concatenated, and so on.
Accessing Values in Tuples
To access values in tuple, use the square brackets for slicing along with the index or indices to
obtain value available at that index. For example –
tup1 = ('physics', 'chemistry', 1997, 2000)
tup2 = (1, 2, 3, 4, 5)
print(tup1[0])
print(tup2[1:5])

When the above code is executed, it produces the following result −


physics
[2, 3, 4, 5]

Updating Tuples
Tuples are immutable which means you cannot update or change the values of tuple elements.
You are able to take portions of existing tuples to create new tuples as the following example
demonstrates –
tup1 = (12, 34.56)
tup2 = (‘abc’, ‘xyz’)
tup3 = tup1 + tup2
print(tup3)
result of above code is: -
(12, 34.56, 'abc', 'xyz')

12 | P a g e
Delete Tuple Elements
Removing individual tuple elements is not possible. There is, of course, nothing wrong with
putting together another tuple with the undesired elements discarded.
To explicitly remove an entire tuple, just use the del statement. For example –
tup1 = ('physics', 'chemistry', 1997, 2000)
print(tup1)
del tup1
print (“After Deleting tup:”)
print tup1

Built-in Tuples Operations

S r.No. Functi on wi th Description

1 len(tuple)

Gives the total length of the tuple.

2 max(tuple)

Returns item from the tuple with max value.

3 min(tuple)

Returns item from the tuple with min value.

4 tuple(seq)

Converts a list into tuple.

13 | P a g e
3. DICTIONARY
Each key is separated from its value by a colon (:), the items are separated by commas, and the
whole thing is enclosed in curly braces. An empty dictionary without any items is written with
just two curly braces, like this: { }.

Keys are unique within a dictionary while values may not be. The values of a dictionary can be
of any type, but the keys must be of an immutable data type such as strings, numbers, or tuples.

Accessing Values in Dictionary


To access dictionary elements, you can use the familiar square brackets along with the key to
obtain its value. Following is a simple example –

dict = {‘Name’:’Zara’,’Age’:7,’Class’:’First’}

print(dict[‘Name’])

Output is :-

Zara

Updating Dictionary

You can update a dictionary by adding a new entry or a key-value pair, modifying an existing
entry, or deleting an existing entry as shown below in the simple example −

dict = {‘Name’:’Zara’,’Age’:7,’Class’:’First’}

dict[‘Age’] = 8 #update existing entry

print(dict[‘Age’])

Output is :-

14 | P a g e
Dictionary Functions & Methods
Python includes the following dictionary functions −

S r.No. Functi on & Me thods wi th Description

1 len(dict)

Gives the total length of the dictionary. This would be equal to the number of items in the
dictionary.

2 str(dict)

Produces a printable string representation of a dictionary

3 type(variable)

Returns the type of the passed variable. If passed variable is dictionary, then it would return a
dictionary type.

4 dict.clear()

R e m ov es all elements of dictionary dict

5 dict.copy()

R eturns a s hallow copy of dictionary dict

6 dict.get(key, default=None)

For key k ey, returns v alue or default if k e y not i n dictionary

7 dict.update(dict2)

A d d s dictionary dict2's k ey-v alues pairs to dict

8 dict.keys(),dict.values()

R eturns list of dictionary dict's k eys ,dict’s v alue

16 | P a g e
FUNCTIONS IN PYTHON
A function is a block of organized, reusable code that is used to perform a single, related action.
Functions provide better modularity for your application and a high degree of code reusing.

As you already know, Python gives you many built-in functions like print(), etc. but you can also
create your own functions. These functions are called user-defined functions.

Defining a Function

Simple rules to define a function in Python.

• Function blocks begin with the keyword def followed by the function name and
parentheses ( ( ) ).

• Any input parameters or arguments should be placed within these parentheses. You can
also define parameters inside these parentheses.

• The first statement of a function can be an optional statement - the documentation string
of the function or docstring.

• The code block within every function starts with a colon (:) and is indented.

• The statement return [expression] exits a function, optionally passing back an expression
to the caller. A return statement with no arguments is the same as return None.

Syntax
def functionname( parameters ):
function_suite
return [expression]

Example
def printer(str):
print(str)

return

16 | P a g e
Calling a Function
Defining a function gives it a name, specifies the parameters that are to be included in the function
and structures the blocks of code.

Once the basic structure of a function is finalized, you can execute it by calling it from another
function or directly from the Python prompt. Following is an example to call
the printer() function.

def printer(str):

print(str)

return

printer(“INDER”)

OUTPUT IS :-

INDER

Function Arguments
You can call a function by using the following types of formal arguments −

• Required arguments
• Keyword arguments

• Default arguments

17 | P a g e
Numeric Matrix Processor

def operations():
while True:
user_choice = int(input("""1. Add matrices\n
2. Multiply matrix by a constant\n
3. Multiply matrices\n
4. Transpose matrix\n
5. Calculate a determinant\n
0. Exit\n
Your choice: """))
if user_choice== 1:
add_matrix()
elif user_choice == 2:
multiply_with_constant()
elif user_choice == 3:
matrix_multiplication()
elif user_choice == 4:
transpose_matrix()
elif user_choice == 5:
dimension = get_dimensions('Enter size of matrix:: ')
matrix = get_matrix(dimension[0d]i,mension[1], 'Enter matrix:
')
print("The result is: ")
print(calc_determinant(matrix))

elif user_choice == 0:
exit()

def get_matrix(rows, columns, input_text):


print(input_text)
matrix = []
for i in range(rows):
row = input().split()
matrix.append([])
for j in range(columns):
matrix[i].append(dataype(row[j]))
return matrix

def get_dimensions(input_text):
return [int(x) for x in input(input_text).split()]

def add_matrix():

18 | P a g e
dimension_1 = get_dimensions('Enter size of first matrix: ')
matrix_1 = get_matrix(dimension_1[0], dimension_1'[E1n]t,er first matrix:
')
dimension_2 = get_dimensions('Enter size of second matrix: ')
matrix_2 = get_matrix(dimension_2[0], dimension_2[1], 'Enter second matrix
:')

if dimension_1 == dimension_2:
matrix_3 = []
for i in range(dimension_1[0]):
matrix_3.append([])
for j in range(dimension_1[1]):
matrix_3[i].append(matrix_1[i][j] + matrix_2[i][j])
print_matrix(matrix_3)
else:
print('ERROR')

def multiply_with_constant():
dimension = get_dimensions('Entseirze of matrix:: ')
matrix = get_matrix(dimension[0], dimension[1], 'Enter matrix:')

constant = dataype(input('Enter constant: '))


matrix_result = []

for i in range(dimension[0]):
matrix_result.append([])
for j in range(dimension[1]):
matrix_result[i].append(matrix[i][j] * constant)
print_matrix(matrix_result)

def matrix_multiplication():
dimension_1 = get_dimensions('Enter soifzefirstmatrix: ')
matrix_1 = get_matrix(dimension_1[0], dimension_1'[E1n]t,er first matrix:
')
dimension_2 = get_dimensions('Enter size of second matrix: ')
matrix_2 = get_matrix(dimension_2[0], dimension_2[1], 'Enter second matrix
:')

if dimension_1[1] == dimension_2[0]:
matrix_product = []
for i in range(dimension_1[0]):
matrix_product.append([])
for j in range(dimension_2[1]):
dot_product = 0
for k in range(dimension_2[0]):
dot_product += matrix_1[i][k] * matrix_2[k][j]
matrix_product[i].append(dot_product)

19 | P a g e
print_matrix(matrix_product)

def transpose_matrix():
functions = int(input('1. Madiinagonal\n'
'2. Side diagonal\n'
'3. Vertical line\n'
'4. Horizontal line\n'
'Your choice: '))

if 1 <= functions <= 4:


dimension_1 = get_dimensions('Enter matrix size: ')
matrix = get_matrix(dimension_1[0], dimension_1[1], 'Enter matrix:')

if functions == 1:
main_daigonal(matrix)
elif functions == 2:
side_diagonal(matrix)
elif functions == 3:
vertical_line(matrix)
elif functions == 4:
horizontal_line(matrix)

def main_daigonal(matrix):
row = len(matrix)
column = len(matrix[0])
transposed_matrix = []

for i in range(row):
transposed_matrix.append([])
for j in range(column):
transposed_matrix[i].append(matrix[j][i])
print_matrix(transposed_matrix)

def side_diagonal(matrix):
row = len(matrix)
column = len(matrix[0])
transposed_matrix = []

for i in range(row):
row = []
for j in range(column):
row.insert(0, matrix[j][i])
transposed_matrix.insert(0, row)
print_matrix(transposed_matrix)

def vertical_line(matrix):

20 | P a g e
column = len(matrix[0])
transposed_matrix = []

for i in range(column):
transposed_matrix.append(matrix[i][::-1])
print_matrix(transposed_matrix)

def horizontal_line(matrix):
column = len(matrix[0])
transposed_matrix = []

for i in range(column):
transposed_matrix.insert(0, matrix[i])
print_matrix(transposed_matrix)

def calc_determinant(matrix):
n = len(matrix)
m = len(matrix[0])
det = 0

if n != m:
print("cannot be found")
else:
if n == 1:
det = matrix[0][0]
elif n == 2:
det = matrix[0][0] * matrix[1][1]ma-trix[1][0] * matrix[0][1]
else:
for j in range(m):
det += matrix[0][j] * calc_cofactor(matrix, 0, j)

return det

def calc_cofactor(matrix, row, col):


return pow((-
1), row + 1 + col +
1) * calc_determinant(get_minor(matrix, row, col))

def get_minor(matrix, a, b):


rows = len(matrix)
cols = len(matrix[0])

minor_matrix = []

for i in range(rows):
minor_matrix.append([])
for j in range(cols):
if i != a and j != b:
minor_matrix[i].append(matrix[i][j])

21 | P a g e
return [row for row in minor_matrix if row]
def print_matrix(matrix):
print('The result is:')
for i in matrix:
print(*i)

def dataype(number):
try:
int(number)
return int(number)
except ValueError:
try:
float(number)
return float(number)
except ValueError:
return None

operations()

OUTPUT IS :-

22 | P a g e
CONCLUSION

After completing this project, I concluded that this project was the good opportunity
to implement my information that I have learnt during my Internship program. This
project is more informative and more helpful for understanding the concept of Python.
This course is only a small and easy one but it is enough to implement my concept.
I can further try much harder to make much more efficient and useful program that
can benefit to others.

24 | P a g e

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy