You are on page 1of 24

A REPORT ON ESSENTIAL SKILLS OF

PYTHON PROGRAMMING FOR PHYSICISTS

Submitted in partial fulfilment of the course requirement of


internship program-I

(28th May – 28th July)

AT

ICFAI UNIVERSITY TRIPURA

Under the guidance of


Dr. Lokesh Mohan

(FACULTY OF SCIENCE AND TECHNOLOGY)


ICFAI UNIVERSITY TRIPURA

SUBMITTED BY --

Chayanika Sarkar (18IUT0080022) Manidipa Das (18IUT0080027)


Mandira Bhowmik (18IUT0080020) Suman Das (18IUT0080019)
Akash Dey (18IUT0080023) Mourita Chakraborty (18IUT0080026)
Bidhan Roy (18IUT0080024)
CERTIFICATION

[TO WHOM IT MAY CONCERN]

This is to certify that Mrs Chayanika Sarkar (18IUT0080022), Ms Manidipa Das


(18IUT0080027), Ms Mandira Bhowmik (18IUT0080020), Mr Suman Das
(18IUT0080019), Mr Akash Dey (18IUT0080023), Ms Mourita Chakraborty

(18IUT0080026) and Mr Bidhan Roy (18IUT0080024), 2nd year students of M.Sc.


Physics course, under ICFAI University Tripura have successfully completed the

Internship program-I at IUT, Kamalghat from 28th May, 2019 to 28th July, 2019. During
this internship program they have sincerely learnt the basics of Python Programming and
have shown keen interest in work assigned to them.

I wish them every success in life.


DECLARATION

The project on Python Programming Language is done by Mrs Chayanika Sarkar


(18IUT0080022), Ms Manidipa Das (18IUT0080027), Ms Mandira Bhowmik
(18IUT0080020), Mr Suman Das (18IUT0080019), Mr Akash Dey (18IUT0080023),
Ms Mourita Chakraborty (18IUT0080026) and Mr Bidhan Roy (18IUT0080024) as

students of M.Sc Physics 2nd year, ICFAI UNIVERSITY TRIPURA.

We declare that this project has not been submitted to any other organization, colleges or
any other institutions for any other purpose.
TABLE OF CONTENTS
SL.NO. TOPICS PAGE NO.
CERTIFICATION

Declaration

Table of Content

Acknowledgement

1 Organization Profile 1
2 Introduction 2
3 Advantages of Python in Programming Languages 3-4
4 Useful Python Packages 5
5 Programmes

i Trajectory of projectile motion using python 6


ii Dot and cross product of two vector using python 7

iii OR Gate Using Python 8


iv AND Gate Using Python 9

v NOT Gate Using Python 10

vi EX-OR Gate using Python 10-11

vii A python program to plot a bar chart to depict the popularity of 12

various programming languages

viii Program in python to multiply two matrices using nested loops 13

ix Pie Chart using Python 14

x Plot sine and cosine over the range {−π, π} 15

xi Number System Conversion(Decimal,Binary,Octal,Hexadecimal) 15

6 Conclusion 16

Acknowledgement
First of all, we would like to express our sincere respect and heartfelt thanks to Dr.
Priyanshu Borthakur sir, Coordinator, Faculty of Science and Technology, ICFAI
University Tripura for showing his keen interest and adequate attention towards student’s
internship program and all the students in the best possible way.

We are thankful to Dr. Lokesh Mohan sir for showing us the path and guiding us with
immense patience because of which we could complete our project.

We would like to thank our respected Pro. V.C. Prof. Biplab Halder and our respected
registrar Dr. A. Ranganath for providing us all the facilities that we would require to
complete the project.

Yours faithfully,

Chayanika Sarkar (18IUT0080022) Manidipa Das (18IUT0080027)

Mandira Bhowmik (18IUT0080020) Suman Das (18IUT0080019)

Akash Dey (18IUT0080023) Mourita Chakraborty (18IUT0080026)

Bidhan Roy(18IUT0080024)
Organisation Profile

ICFAI University Tripura is a private University located at Kamalghat, Tripura, India. It


was established in 2004 through an act of State Legislature (Tripura Act 8 of 2004).UGC
has approved the university under Section 2(f) of the UGC Act, 1956 and hence included
in the list of universities maintained by UGC under Section 2(f) of the UGC Act, 1956.
ICFAI was established in 1984 not for profit but for society with the broad objective of
empowering citizens through world class quality education. The institute announced its
arrival into the Indian education by innovatively launching the ICFAI program in 1985.
The ICFAI program was a unique program in management and technology.

1
Introduction

In his profession a physicist needs to perform multiple tasks such as tedious data
acquisitions, lengthy calculations and effective presentation of the raw and processed
data. Thanks to the technology, all these demanding and time consuming chores can be
achieved with the help of computers in a tiny fraction of effort and time required
otherwise. Therefore programming skills have become an essential kit in the bag of every
physicist irrespective of him being an experimentalist or theoretician.

Python is a widely used general-purpose, high level programming language. It was


initially designed by Guido van Rossum in 1991 and developed by Python Software
Foundation. Python is based on two programming languages:

ABC language, a teaching language created as a replacement of BASIC and

Modula-3

It was mainly developed for emphasis on code readability, and its syntax allows
programmers to express concepts in fewer lines of code.

Python is a programming language that lets you work quickly and integrate systems more
efficiently. It is an easy to learn yet powerful object oriented programming language.

Keeping this in mind we chose to learn python programming as part of our Summer
Internship program wherein we have learnt a few tricks of the trade such as how to
perform simple calculations in python and how to plot various kinds of graphs and
diagrams in python. In this report we have presented some basic Python packages which
are useful for Physicists.

We also present the advantages of python programming language as compared to other


programming languages and a few Python programs with their output. By seeing this
report, one can understand how much simpler python programming’s syntax is and how
we can solve very complex problems also with simple python programming code. Below
we list some of the key advantages of using Python as a preferred language:

2
Advantages of python in programming languages:

1. Easy to use:
Python is compact and easy to use object-oriented language with simple syntax
rules. It is a high level language and hence very programmer friendly.

2. Expressive Language:
Python’s expressiveness means it is more capable of expressing the code’s
purpose than many other languages. Reason being- fewer lines of code and
simpler syntax.
For example:

In C++: Swap values In python: Swap


values
int a=2,b=3,c; a,b=2,3
c=a; a,b=b,a
a=b;
b=c;

3. Interpreted language:
Python is an interpreted language, not a compiled language. This means that the
python installation interprets and executes the code line by line at a time. It makes
python an easy to debug language and suitable for beginners to advanced users.

4. Its completeness:
When we install python, we get everything we need to do real work. We do not
need to download and install additional libraries. All types of required
functionality is available through various modules of python standard library.

5. Cross-platform language:
Python can run equally well on variety of platforms- windows, Linux/Unix,
Macintosh, super computers, smart phones etc. And that makes python a true cross
platform language. On other words, python is a portable language.

6. Free and Open Source:


Python language is freely available i,e, without any cost and not only is it free, its

3
source code is also available, i,e, it is open source also.
7. Variety of usage/applications:
Python has evolved into a powerful, complete and useful language over these
years. These days python is being used in many diverse fields/ applications, some
of which are:
 Scripting
 Data acquisition
 Data processing
 Performing Mathematical operations
 Plotting
 Data presentation
 Web applications
 Game development
 GUI programs
 System administrations
 Rapid Prototyping

4
Some useful Python packages:

 Numpy:
Numpy stannds for Numerical Python.It is not another programming language but a
Python extension module. It provides fast and efficient operations on arrays of
homogeneous data. Numpy extends python into a high-level language for manipulating
numerical data, similiar to MATLAB.

 Scipy:
Scipy stands for Scientific Python.It is a free and open-
source Python library used for scientific computing and technical computing.Scipy
builds on the Numpy array object and is part of the Numpy stack which includes tools
like Matplotlib, pandas and Sympy, and an expanding set of scientific computing
libraries.

 Matplotlib:
Matplotlib is a plotting library for the Python programming language and its
numerical mathematics extension Numpy. It provides an object-oriented API for
embedding plots into applications using general-purpose GUI toolkits like Tkinter,
Wxpython,GTK+ etc.

5
PROGRAMMES:

1.Trajectory of projectile motion using python:

importnumpy as np
importmatplotlib.pylab as plot
import math as m
#initialize variables
#velocity, gravity
v = 30
g = 9.8
#increment theta 25 to 60 then find t, x, y
#define x and y as arrays
theta = np.arange(m.pi/6, m.pi/3, m.pi/36)
t = np.linspace(0, 5, num=100) # Set time as 'continous' parameter.
for i in theta: # Calculate trajectory for every angle
x1 = []
y1 = []
for k in t:
x = ((v*k)*np.cos(i)) # get positions at every point in time
y = ((v*k)*np.sin(i))-((0.5*g)*(k**2))
x1.append(x)
y1.append(y)
p = [i for i, j in enumerate(y1) if j < 0] # Don't fall through the floor
for i in sorted(p, reverse = True):
del x1[i]
del y1[i]
plot.plot(x1, y1) # Plot for every angle
plot.show() # And show on one graphic

Output:-

6
2.Dot and cross product of two vector using python:

# Python3 implementation for dot product


# and cross product of two vector.
  n = 3
# Function that return
# dot product of two vector array.
defdotProduct(vect_A, vect_B):
   product = 0
 # Loop for calculate cot product
    for i in range(0, n):
  product = product + vect_A[i] * vect_B[i]
  return product
# Function to find
# cross product of two vector array.
defcrossProduct(vect_A, vect_B, cross_P):
  
    cross_P.append(vect_A[1] * vect_B[2] - vect_A[2] * vect_B[1])
    cross_P.append(vect_A[0] * vect_B[2] - vect_A[2] * vect_B[0])
    cross_P.append(vect_A[0] * vect_B[1] - vect_A[1] * vect_B[0])
  
# Driver function
if __name__=='__main__':
    vect_A = [3, -5, 4]
    vect_B = [2, 6, 5]
    cross_P = []

# dotProduct function call


    print("Dot product:", end=" ")
    print(dotProduct(vect_A, vect_B))
# crossProduct function call
    print("Cross product:", end=" ")
    crossProduct(vect_A, vect_B, cross_P)
# Loop that print
# cross product of two vector array.
    for i in range(0, n):
        print(cross_P[i], end=" ")

Output :

Dot product:-4
Cross product:-49 7 28

7
3. OR Gate Using Python:

# Python3 program to illustrate


# working of OR gate
def OR(a, b):
if a == 1:
        return True
    elif b == 1:
        return True
    else:
        return False
# Driver code
if __name__=='__main__':
    print(OR(0, 0))
   print("+---------------+----------------+")
    print(" | OR Truth Table | Result |")
    print(" A = False, B = False | A AND B =",OR(False,False)," | ")
    print(" A = False, B = True | A AND B =",OR(False,True)," | ")
    print(" A = True, B = False | A AND B =",OR(True,False)," | ")
    print(" A = True, B = True | A AND B =",OR(True,True)," | ")

Output:-

False
+---------------+----------------+
| OR Truth Table | Result |
A = False, B = False | A AND B = False |
A = False, B = True | A AND B = True |
A = True, B = False | A AND B = True |
A = True, B = True | A AND B = True |

8
4. AND Gate Using Python:

# Python3 program to illustrate


# working of AND gate
def AND (a, b):
    if a == 1 and b == 1:
        return True
    else:
        return False
# Driver code
if __name__=='__main__':
    print(AND(1, 1))
    print("+---------------+----------------+")
    print(" | AND Truth Table | Result |")
    print(" A = False, B = False | A AND B =",AND(False,False)," | ")

    print(" A = False, B = True | A AND B =",AND(False,True)," | ")


    print(" A = True, B = False | A AND B =",AND(True,False)," | ")
    print(" A = True, B = True | A AND B =",AND(True,True)," | ")

Output:-

True
+---------------+----------------
| AND Truth Table | Result |
A = False, B = False | A AND B = False |
A = False, B = True | A AND B = False |
A = True, B = False | A AND B = False |
A = True, B = True | A AND B = True |

9
5. NOT Gate Using Python:

# Python3 program to illustrate


# working of Not gate
  
def NOT(a):
    if(a == 0):
        return 1
    elif(a == 1):
        return 0
# Driver code
if __name__=='__main__':
    print(NOT(0))
    print("+---------------+----------------+")
    print(" | NOT Truth Table | Result |")
    print(" A = False | A NOT =",NOT(False)," | ")
    print(" A = True, | A NOT =",NOT(True)," | ")
   
Output:-
1
+---------------+----------------+ |
NOT Truth Table | Result |
A = False | A NOT = 1 |
A = True, | A NOT = 0 |

6. EX-OR Gate using Python:

# Python3 program to illustrate


# working of Xorgate
  
def XOR (a, b):
    if a != b:

10
        return 1
    else:
 return 0
  
# Driver code
if __name__=='__main__':
    print(XOR(5, 5))
 
    print("+---------------+----------------+")
    print(" | XOR Truth Table | Result |")
    print(" A = False, B = False | A AND B =",XOR(False,False)," | ")
    print(" A = False, B = True | A AND B =",XOR(False,True)," | ")
    print(" A = True, B = False | A AND B =",XOR(True,False)," | ")
    print(" A = True, B = True | A AND B =",XOR(True,True)," | ")

Output:-
0
+-------------+----------------+
| XOR Truth Table | Result |
A = False, B = False | A AND B = FALSE |
A = False, B = True | A AND B = TRUE |
A = True, B = False | A AND B = TRUE |
A = True, B = True | A AND B = FALSE |

11
7.A python program to plot a bar chart to depict the popularity of various
programming languages:
Answer:
import numpy as np
import matplotlib.pyplot as plt
objects=('DotNet','C++','java','python','C','CGI/PERL')
y_pos=np.arange(len(objects))
performance=[8,10,9,20,4,1]
plt.bar(y_pos,performance,align='center',color='blue')
plt.xticks(y_pos,objects)
plt.ylabel('usage')
plt.title('programming language usage')
plt.show( )

Output:

12
8.Program in python to multiply two matrices using nested loops:
Answer:
X = [[12,7,3],
[4 ,5,6],
[7 ,8,9]]

Y = [[5,8,1,2],
[6,7,3,0],
[4,5,9,1]]

result = [[0,0,0,0],
[0,0,0,0],
[0,0,0,0]]
for i in range(len(X)): for j
in range(len(Y[0])): for k in
range(len(Y)):
result[i][j] += X[i][k] * Y[k][j] for r
in result:
print(r)

Output:
13
9. Pie Chart using Python:
import matplotlib.pyplot as plt
labels = 'Python', 'C++', 'Ruby', 'Java' sizes
= [215, 130, 245, 210]
colors = ['gold', 'yellowgreen', 'lightcoral', 'lightskyblue'] explode
= (0.1, 0, 0, 0)
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
autopct='%1.1f%%', shadow=True, startangle=140)

Output:-

14
10.Plot sine and cosine over the range {−π, π} ;-
from pylab import ∗
x = a r an ge (−pi , pi , pi / 1 0 0 )
pl o t ( x , s i n ( x ) , ’ b−’ , l a b e l=’ s i n e ’ )
pl o t ( x , c o s ( x ) , ’ g−−’ , l a b e l=’ c o s i n e ’ ) x l a b e
l ( ’ x v al u e ’ )
y l a b e l ( ’ t r i g f u n c ti o n v al u e ’ ) xlim
(−pi , pi )
ylim ( −1 ,1)
l e g e n d ( l o c=’ upper l e f t ’ )
show( )

Output:-

11.Number System
Conversion(Decimal,Binary,Octal,Hexadecimal):-

>>>bin(25)
‘0b11001’
>>>0b0101 5
>>>Oct(125)
‘0o31’
>>>Hex(10)
‘0xa’
15
Conclusion:
In the end, we would like to conclude that the above programmes could have been made in
more efficient way. We have given our level best for drafting this report on python
programming. We are almost content with the outcome and are looking forward to learn from
its flaws and try to improvise our skills on python programming in future. We hope this report
reaches the expectations of our respected teachers.

16

You might also like