EXPERIMENT NO - 1
AIM:
Write a program to demonstrate different number data types in Python.
Apparatus Required:
PYTHON 3.5
SOURCECODE:
a=5
print(a, "is of type", type(a))
a = 2.0
print(a, "is of type", type(a))
a = 1+2j
print(a, "is complex number?", isinstance(1+2j,complex))
INPUT AND OUTPUT:
5 is of type <class 'int'>
2.0 is of type <class 'float'>
(1+2j) is complex number? True
5 is of type <class 'int'>
2.0 is of type <class 'float'>
(1+2j) is complex number? True
CONCLUSIONS:
Different number data types has been studied.
Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 1
EXPERIMENT NO - 2
AIM:
Write a program to perform different Arithmetic Operations on numbers in Python.
Apparatus Required:
PYTHON 3.5
SOURCECODE:
x = 15
y=4
Output: x + y
= 19 print('x + y
=',x+y)
Output: x - y
= 11 print('x - y
=',x-y)
Output: x * y
= 60 print('x * y
=',x*y)
Output: x / y =
3.75 print('x / y
=',x/y)
Output: x ** y =
print('x ** y =',x**y)
INPUT AND OUTPUT:
x + y = 19
x - y = 11
x * y = 60
x / y = 3.75
x // y = 3
x ** y = 50625
CONCLUSIONS:
Different arithmetic operations on numbers in python have been studied.
Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 2
EXPERIMENT NO -3
AIM:
Write a program to create, concatenate and print a string and accessing sub string from a
given string.
Apparatus Required:
PYTHON 3.5
SOURCECODE:
all of the following are equivalent
my_string = 'Hello' print(my_string)
my_string = "Hello"
print(my_string)
my_string = '''Hello'''
print(my_string)
triple quotes string can extend multiple lines my_string
= """Hello, welcome to
the world of Python"""
print(my_string)
c=" mlritm"
print(my_string+c)
substring function
print(my_string[5:11])
INPUT AND OUTPUT:
Hello
Hello
Hello
Hello, welcome to
the world of Python
Hello, welcome to
the world of Python mlritm
, welc
CONCLUSION :
A string and accessing sub- string fron a given string has been studied.
Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 3
EXPERIMENT NO -4
AIM:
Write a python script to print the current date in the following format “Sun May 29
02:26:23 IST 2017”.
Apparatus Required:
PYTHON 3.5
SOURCECODE:
from datetime import date
today =date.today()
# dd/mm/YY
d1 =today.strftime("%d/%m/%Y")
print("d1 =", d1)
Textual month, day and year
d2 =today.strftime("%B %d,
%Y") print("d2 =", d2)
mm/dd/y
d3 =today.strftime("%m/%d/%y")
print("d3 =", d3)
Month abbreviation, day and
year d4 =today.strftime("%b-%d-
%Y") print("d4 =", d3)
INPUT AND OUTPUT:
d1 = 25/12/2018
d2 = December 25, 2018
d3 = 12/25/18
d4 = 12/25/18
CONCLUSION:
A python script to print the current date in the given format has been studied.
Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 4
EXPERIMENT NO -5
AIM:
Write a program to create, append, and remove lists in python.
Apparatus Required:
PYTHON 3.5
SOURCECODE:
my_list = ['p','r','o','b','l','e','m']
my_list.remove('p')
Output: ['r', 'o', 'b', 'l', 'e',
'm'] print(my_list)
Output: 'o'
print(my_list.pop(1))
Output: ['r', 'b', 'l', 'e',
'm'] print(my_list)
Output: 'm'
print(my_list.pop())
Output: ['r', 'b',
'l', 'e']
print(my_list)
my_list.clear()
Output: []
print(my_list)
INPUT AND OUTPUT:
my_list=['p','r','o','b','l','e','m']
>>>my_list[2:3]=[]
>>>my_list
['p','r','b','l','e','m']
>>>my_list[2:5]=[]
>>>my_list
['p','r','m']
CONCLUSION :
A program has been studied to create , append and remove lists in python .
Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 5
EXPERIMENT NO -6
AIM:
Write a program to demonstrate working with tuples in python.
Apparatus Required:
PYTHON 3.5
SOURCECODE:
empty tuple
Output: ()
my_tuple =
()
print(my_t
uple)
tuple having integers
Output: (1, 2, 3)
my_tuple = (1,
2, 3)
print(my_tuple)
tuple with mixed datatypes
Output: (1, "Hello",
3.4) my_tuple = (1,
"Hello", 3.4)
print(my_tuple)
nested tuple
Output: ("mouse", [8, 4, 6], (1, 2,
3)) my_tuple = ("mouse", [8, 4, 6],
(1, 2, 3)) print(my_tuple)
tuple can be created without parentheses
also called tuple packing
Output: 3, 4.6, "dog"
my_tuple = 3, 4.6, "dog"
print(my_tuple)
tuple unpacking is also possible
Output:
Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 6
3
4.6
dog
a, b, c = my_tuple
print(a)
print(b)
print(c)
INPUT AND OUTPUT
()
(1, 2, 3)
(1, 'Hello', 3.4)
('mouse', [8, 4, 6], (1, 2, 3))
(3, 4.6, 'dog')
3
4.6
dog
CONCLUSION :
Working with tuples has been studied in python .
Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 7
EXPERIMENT NO -7
AIM:
Write a program to demonstrate working with dictionaries in python.
Apparatus Required:
PYTHON 3.5
SOURCECODE:
my_dict = {'name':'Jack', 'age': 26}
Output: Jack
print(my_dict['na
me'])
Output: 26
print(my_dict.get('age'))
Trying to access keys which doesn't exist throws error
my_dict.get('address')
my_dict['address']
INPUT AND OUTPUT:
Jack
26
CONCLUSION :
Working with dictionaries has been studied in python.
Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 8
EXPERIMENT NO -8
AIM:
Write a python program to find largest of three numbers.
Apparatus Required:
PYTHON 3.5
SOURCECODE:
Python program to find the largest number among the three input numbers
change the values of num1, num2 and num3
for a different result
num1 = 10
num2 = 14
num3 = 12
uncomment following lines to take three numbers from
user #num1 = float(input("Enter first number: "))
#num2 = float(input("Enter second number: "))
#num3 = float(input("Enter third number: "))
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number between",num1,",",num2,"and",num3,"is",largest)
INPUT AND OUTPUT:
The largest number between 10, 14 and 12 is 14.0
CONCLUSION :
A prgram in which largest of three number has been studied in python .
Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 9
EXPERIMENT NO -9
AIM:
Write a Python program to convert temperatures to and from Celsius,
Fahrenheit. [ Formula : c/5 = f-32/9 ]
Apparatus Required:
PYTHON 3.5
SOURCECODE:
Python Program to convert temperature in celsius to fahrenheit
change this value for a different result
celsius = 37.5
calculate fahrenheit
fahrenheit = (celsius * 1.8)
+ 32
print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(celsius,fahrenheit))
INPUT ANDOUTPUT:
37.5 degree Celsius is equal to 99.5 degree Fahrenheit
CONCLUSION :
Conversion of temperature has been studied .
Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 10
EXPERIMENT NO -10
AIM:
Write a Python program to construct the following pattern, using a nested for loop
*
**
***
****
*****
****
***
**
*
Apparatus Required:
PYTHON 3.5
SOURCECODE:
n=5;
for i in range(n):
for j in range(i):
print ('* ', end="")
print('')
for i in range(n,0,-
1):
for j in range(i):
print('* ', end="")
print('')
INPUT ANDOUTPUT:
*
**
***
****
*****
****
***
**
*
CONCLUSION :
A program has been studied to construct the pattern , using a nested loop in python .
Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 11