Manvi Report
Manvi Report
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
2. History .......................................................................................... 5
2. Operator .............................................................................................. 7
1. List .............................................................................................. 11
2. Tuple ......................................................................................... 13
3. Dictionary .................................................................................. 15
4. Functions ......................................................................................... 17
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 Interactive − You can actually sit at a Python prompt and interact
with the
interpreter directly to write your programs.
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).
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.
• Easy-to-read − Python code is more clearly defined and visible to the eyes.
• A broad standard library − Python's bulk of the library is very portable and cross-
platform
• Interactive Mode − Python has support for an interactive mode which allows
interactive
• Portable − Python can run on a wide variety of hardware platforms and has the
• Extendable − You can add low-level modules to the Python interpreter. These
modules
• 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 provides very high-level dynamic data types and supports dynamic type checking.
• 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
# Output: x - y = 11
# 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
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
#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.
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.
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.
11 | P a g e
List Functions & Methods
Python includes the following list functions −
1 len(list)
2 max(list)
3 min(list)
4 list(seq)
5 list.append(obj)
6 list.insert(index, obj)
7 list.reverse()
8 list.sort()
9 list.remove(obj)
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])
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
1 len(tuple)
2 max(tuple)
3 min(tuple)
4 tuple(seq)
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.
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’}
print(dict[‘Age’])
Output is :-
14 | P a g e
Dictionary Functions & Methods
Python includes the following dictionary functions −
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)
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()
5 dict.copy()
6 dict.get(key, default=None)
7 dict.update(dict2)
8 dict.keys(),dict.values()
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
• 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_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:')
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 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
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