You are on page 1of 9

SVKM’s NMIMS

Mukesh Patel School of Technology Management & Engineering


Computer Engineering Department
Program: BTech SEM VI

Course: Programming Laboratory- III

List of Experiments

w.e.f. 11th Dec 2018


Faculty: Prof. Kamal Mistry

Exp No. Title Prerequisite* CO#


1 To understand the syntax, commands Basic knowledge of CO1
and operators in Python programming computer programming I and
(Introduction) II

2.
3.
4
5
6
7
8
9
10
11

* Students are expected to be ready with the prerequisite before attending the lab
Program No.01
PART A
(PART A: TO BE REFFERED BY STUDENTS)

A.1 AIM: - To understand the syntax and commands in Python programming


(Introduction)

A.2 Prerequisite
Computer Programming I, and II

A.3 Outcome
After successful completion of this experiment students will be able to

1. Installation of Python (IDLE)


2. Understand the basic syntax , variables , identifiers and commands in Python

A.4 Theory

Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming


language. It was created by Guido van Rossum during 1985- 1990. Like Perl, Python source
code is also available under the GNU General Public License (GPL).
Installing Python
Python distribution is available for a wide variety of platforms. You need to download only the
binary code applicable for your platform and install Python.

If the binary code for your platform is not available, you need a C compiler to compile the source
code manually. Compiling the source code offers more flexibility in terms of choice of features that
you require in your installation

Open a Web browser and go to https://www.python.org/downloads

Run the downloaded file.


Open the Python command window or IDLE shell script

Syntax:

INDENTATION: Matters a lot in python. We denote blocks of code through indentation

Operators:

• Arithmetic Operators (+,-,*,/,%, **,//)

• Comparison (Relational) Operators (==,>,<,>=,<=,!=)

• Assignment Operators (=,+=,-=,/=…

• Logical Operators (and,or, not….)

• Bitwise Operators (&,^,|,<<,>>)

• Membership Operators (in , not in)

• Identity Operators (is,is not)

Program 1: On operators
Type each of the following expressions. Copy the values in observation book.

a. (4+5)*8/2

b. 4+5*8/2
Compare answer with previous expression

c. 5//4

d. 3 ** 3, 3.0**3
e. x=true y=false

x and y

f. x=10 y=4 compute x|y, x<<2, x>>2

g. x1= ‘hello’ y1=’hello’


find output for: x1 is not y1

h. x= ‘hello world’
find output for: h in x, hello not in x

i. Type the following program


>>> C = 20.9
>>> type(C)
<type ‘float’>
>>> D = int(C)
>>> type(D)
<type ‘ínt’>
>>> D

j. Find error:
x=1;
print ’sin(%g)=%g’ % (x, sin(x))

Program 2: On flow control

1. Write a program in python to find if the sides given form a triangle. If so


find out whether the triangle is equilateral, isosceles or scalene.

2. Write a program in python to find out if the given year is leap year

3. Write a program to find if given number is Armstrong number


PART B

(PART B: TO BE COMPLETED BY STUDENTS)


(Students must submit the soft copy as per following segments within two hours of the
practical. The soft copy must be uploaded on the Blackboard or emailed to the concerned
lab in charge faculties at the end of the practical in case the there is no Black board access
available)
Roll No. B004 Name: HARSH AGARWAL
Program: B.TECH Division: B
Semester: 5 Batch : B1
Date of Experiment: 12.12.2018 Date of Submission: 12.12.2018
Grade :

B.1 Software Code written by student:


(Paste your Python code completed during the 2 hours of practical in the lab here)

>>> (4+5)*8/2
36.0

>>> 4+5*8/2
24.0

>>> 5//4
1

>>> 3**3
27
>>> 3.0**3
27.0
>>> x = True
>>> y =False
>>> x and y
False

>>> x = 10
>>> y = 4
>>> x|y
14
>>> x<<2
40
>>> x>>2
2

>>>x1= 'hello'
>>>y1=’hello’
>>> x1 is not y1
False

>>> 'h' in x
True
>>> 'hello' not in x
False

>>> C=20.9
>>> type(C)
<class 'float'>
>>> D = int(C)
>>> type(D)
<class 'int'>
>>> D
20
PROGRAM 2 :

1.
a = int(input("side 1 : "))
b = int(input("side 2 : "))
c = int(input("side 3 : "))
s = (a+b+c)/2.0
if(s>a and s>b and s>c):
if(a==b and a==c):
print ("EQUILATERAL")
elif(a==b or b==c or a ==c ):
print ("ISOCELES")
else:
print ("SCALENE")

2.
year = int(input("ENTER YEAR : "))
if(year % 400 == 0):
print ("LEAP YEAR")
elif(year % 100 == 0):
print("NOT LEAP YEAR")
elif(year % 4 == 0):
print("LEAP YEAR")

3. num = int(input("ENTER NUMBER : "))


sum = 0
a = num
while (num > 0):
r = int(num % 10)
num = int(num /10)
sum += r**3

if(a == sum):
print ("ARMSTRONG NUMBER")
else:
print("NOT ARMSTRONG NUMBER")
B.2 Input and Output:
(Paste your program input and output in following format. If there is error then paste the
specific error in the output part. In case of error with due permission of the faculty extension
can be given to submit the error free code with output in due course of time. Students will be
graded accordingly.)

PROGRAM2:

1.
side 1 : 3
side 2 : 3
side 3 : 4
ISOCELES

side 1 : 3
side 2 : 4
side 3 : 5
SCALENE

side 1 : 3
side 2 : 3
side 3 : 3
EQUILATERAL

2.
ENTER YEAR : 1900
NOT LEAP YEAR

ENTER YEAR : 2008


LEAP YEAR

ENTER YEAR : 2000


LEAP YEAR

3.
ENTER NUMBER : 371
ARMSTRONG NUMBER
ENTER NUMBER : 123
NOT ARMSTRONG NUMBER

B.3 Conclusion:
(Students must write the conclusion as per the attainment of individual outcome listed above
and learning/observation noted in section B.1)

You might also like