You are on page 1of 28

PROGRAM : MASTER OF COMPUTER APPLICATIONS

COURSE NAME : DATA ANALYTICS LABORATORY


COURSE CODE : 20MCA28
SEMESTER : 2nd SEMESTER
FACULTY : CHANDRIKA M & PAVITHRA B
PART A

1. Write a program to illustrate various data types in python.


2. Write a program to print the sum of numbers in a range by taking lower bound and upper bound
as input from the user.
3. Write a program to calculate the distance between two points taking input from the user.

Solution: Distance can be calculated using the two points (x1, y1) and (x2, y2), the distance d between these points is
given by the formula:

for e.g: let (x1, y1) = (10,9) and (x2, y2) = (4, 1)
then (x2 - x1)2 = (10 - 4)2 = 62 = 36 and
(y2 - y1)2 = (9 - 1)2 = 82 = 64 now 64 + 36 = 100 and
100 is square root of 10
Therefore, the distance between (10, 9) and (4 ,1) is 10
4. Write a program to demonstrate branching statements in python.
5. Write a program to demonstrate list and tuple, set and dictionary in python.

List Tuple Set Dictionary

List is a non-
Tuple is also a non- Set data structure is
homogeneous data Dictionary is also a
homogeneous data also non-
structure which stores non-homogeneous data
structure which stores homogeneous data
the elements in single structure which stores
single row and multiple structure but stores in
row and multiple rows key value pairs
rows and columns single row
and columns

List can be represented Tuple can be represented Set can be represented Dictionary can be
by [ ] by ( ) by { } represented by {:}

Set will not allow


List allows duplicate Tuple allows duplicate Set will not allow
duplicate elements but
elements elements duplicate elements
keys are not duplicated

List can use nested Tuple can use nested Set can use nested Dictionary can use
among all among all among all nested among all

Example: {1:A, 2:B, 3:C,


Example: [1, 2, 3, 4, 5] Example: (1, 2, 3, 4, 5) Example: {1, 2, 3, 4, 5}
4:D, 5:E}

Dictionary can be
List can be created Tuple can be created Set can be created
created
using list() function using tuple() function. using set() function
using dict() function.
Set is mutable i.e we
List is mutable i.e we Tuple is immutable i.e we Dictionary is mutable.
can make any changes
can make any changes can not make any changes But Keys are not
in set. But elements
in list. in tuple duplicated.
are not duplicated.

List is ordered Tuple is ordered Set is unordered Dictionary is ordered

Creating a set Creating an empty


Creating an empty list Creating an empty Tuple
a = set() dictionary
l = [] t = ()
b = set(a) d = {}
6. Write a program to display current date, time and calendar by importing corresponding modules.

Strftime() method

➢ The strftime() method returns a string representing date and time using date, time or datetime object.
➢ The program below converts a datetime object containing current date and time to different string
formats.
➢ In the above program, %Y, %m, %d etc. are format codes. The strftime() method takes one or more
format codes as an argument and returns a formatted string based on it.

How it works?
Step1: We imported datetime class from the datetime module. It's because the object of datetime class
can access strftime() method.
Step2: The datetime object containing current date and time is stored in now variable.
Step3: The strftime() method can be used to create formatted strings.
Step4: The string you pass to the strftime() method may contain more than one format codes.

Directive Meaning Example


%a Abbreviated weekday name. Sun, Mon, ...
%A Full weekday name. Sunday, Monday, ...
%w Weekday as a decimal number. 0, 1, ..., 6
%d Day of the month as a zero-padded decimal. 01, 02, ..., 31
%-d Day of the month as a decimal number. 1, 2, ..., 30
%b Abbreviated month name. Jan, Feb, ..., Dec
%B Full month name. January, February, ...
%m Month as a zero-padded decimal number. 01, 02, ..., 12
%-m Month as a decimal number. 1, 2, ..., 12
%y Year without century as a zero-padded decimal number. 00, 01, ..., 99
%-y Year without century as a decimal number. 0, 1, ..., 99
%Y Year with century as a decimal number. 2013, 2019 etc.
%H Hour (24-hour clock) as a zero-padded decimal number. 00, 01, ..., 23
%-H Hour (24-hour clock) as a decimal number. 0, 1, ..., 23
%I Hour (12-hour clock) as a zero-padded decimal number. 01, 02, ..., 12
%-I Hour (12-hour clock) as a decimal number. 1, 2, ... 12
%p Locale’s AM or PM. AM, PM
%M Minute as a zero-padded decimal number. 00, 01, ..., 59
%-M Minute as a decimal number. 0, 1, ..., 59
%S Second as a zero-padded decimal number. 00, 01, ..., 59
%-S Second as a decimal number. 0, 1, ..., 59
%f Microsecond as a decimal number, zero-padded on the 000000 - 999999
left.
%z UTC offset in the form +HHMM or -HHMM.
%Z Time zone name.
%j Day of the year as a zero-padded decimal number. 001, 002, ..., 366
%-j Day of the year as a decimal number. 1, 2, ..., 366
%U Week number of the year (Sunday as the first day of the 00, 01, ..., 53
week). All days in a new year preceding the first Sunday
are considered to be in week 0.
%W Week number of the year (Monday as the first day of the 00, 01, ..., 53
week). All days in a new year preceding the first
Monday are considered to be in week 0.
%c Locale’s appropriate date and time representation. Mon Sep 30 07:06:05 2013
%x Locale’s appropriate date representation. 09/30/13
%X Locale’s appropriate time representation. 07:06:05
%% A literal '%' character. %
7. Write a program to check whether a list contains an even number.
8. Write a python program to demonstrate working of iterators using an example type that iterates
given the first and last number.
PART B
1. Design a mini-game of ‘Rock-Paper-Scissor’ using python code.
2. Display the details of a particular file.
3. Analysis of the contents a text file.

Step1: Create a text file with any contents of your choice. (Filename: MyTextFile.txt)
Step2: Create Python file and type the following code. (Filename: TextFileAnalysis.py)
Step 3: Run the file from command prompt and explore all the options.

(Sample output is given below)


4. Plot bar chart and pie chart to display the popularity of programming languages.
Output:

Note: The values can also contain decimal values, but make sure the total value should be 100.

You might also like