Lab Sneha
Lab Sneha
CERTIFICATE
This is to certify that Mr.Dheeraj Basavaraj Iti bearing roll no. 28 of MCA
INDEX
Exp Date of
. Title of Experiment Execution Sign.
no.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
Lab No. 1&2
Q1) Implement a python program to display the current data and time.
import datetime
now=datetime.datetime.now()
print("current date and time:")
print(now.strftime("%y-%m-%d %H:%M:%S"))
Output:-
Q2) Implement a python program that calculates the area of a circle based on the radius
entered by the user.
Output:-
Lab No. 3,4,5,6
x=[[12,7,3],
[4,5,6],
[7,8,9]]
y=[[5,4,6,2],
[3,7,8,1],
[1,2,3,4]]
r=[[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)):
r[i][j]+=x[i][k]*y[k][j]
for r1 in r:
print(r1)
Output:-
Q2) Implement a python program that accepts a sequence of comma-separated numbers
from the user and generates a list and a tuple of those numbers.
Output:-
Q3) Implement function overloading with differnt function signatures
class OverloadedFunctions:
def _init_(self):
pass
def add(self, a, b):
return a + b
def add(self, a, b, c):
return a + b + c
functions =
OverloadedFunctions() result1 =
functions.add(2, 3) result2 =
functions.add(2, 3, 4) print(result1,
result2)
Output:-
Q4) Implementation concept of class,instances and inheritance
class Animal:
def speak(self):
print("Animal Speaking")
class Dog(Animal):
def bark(self):
print("dog barking")
d = Dog()
d.bark()
d.speak()
Output:-
Lab 7 & 8
Q1) Write a python program that takes a text file as input and returns the number of
words of a given text file
def count_words(s):
with open(s) as f:
data=f.read()
data.replace(","," ")
return len(data.split(" "))
print(count_words("s.txt"))
Output:-
Q2) Write a python program to check in which directory you are working.
import os
print(os.getcwd())
Output:-
Lab 9, 10 & 11
Q1) Implement python program using a numpy module create an array and check the
following:Types of array,Axix of array,shape of the array and types of elements in
array
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6]])
print("Array:")
print(arr)
print("\nType of array:", type(arr))
print("\nNumber of axes (dimensions) of the array:", arr.ndim)
print("\nShape of the array:", arr.shape)
print("\nType of elements in the array:", arr.dtype)
Output:-
Q2) Implement python program using mumpy array inexing to access the element on
the 2nd row,5th column.
import numpy as np
arr = np.array([[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15]])
element = arr[1, 4]
print("Element at the 2nd row, 5th column:", element)
Output:-
Q3) Implement python program using numpy array reshape from 1D to 2D
import numpy as np
arr_1d = np.array([1, 2, 3, 4, 5, 6, 7,
8]) arr_2d = arr_1d.reshape(2, 4)
print("Original 1D array:")
print(arr_1d)
print("\nReshaped 2D array:")
print(arr_2d)
Output:-
Lab 12, 13, 14 & 15
Q1) Write a Python program to plot two or more lines with different styles.
Output:-
Q2) Write a Python program to draw line charts of the financial data of Alphabet Inc.
between October 3, 2016 to October 7, 2016. Sample Financial data (fdata.csv):
Date,Open,High,Low,Close 10-03-16,774.25,776.065002,769.5,772.559998 10-04-
16,776.030029,778.710022,772.890015,776.429993
10-05-16,779.309998,782.070007,775.650024,776.469971 10-06-
16,779,780.47998,775.539978,776.859985 10-07-
16,779.659973,779.659973,770.75,775.080017
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('fdata.csv')
df['Date'] = pd.to_datetime(df['Date'], format='%m-%d-%y')
start_date = '2016-10-03'
end_date = '2016-10-07'
filtered_df = df[(df['Date'] >= start_date) & (df['Date'] <= end_date)]
plt.figure(figsize=(10, 6))
plt.plot(filtered_df['Date'], filtered_df['Close'], marker='o', linestyle='-')
plt.title('Alphabet Inc. Stock Prices (Oct 3, 2016 - Oct 7, 2016)')
plt.xlabel('Date')
plt.ylabel('Closing Price')
plt.grid(True)
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
Output:-
Q3) Write a Python programming to display a bar chart of the popularity of
programming Languages. Use different color for each bar. Sample data:
Programming languages: Java, Python, PHP, JavaScript, C#, C++ Popularity: 22.2,
17.6, 8.8, 8, 7.7, 6.7
Output:-
Q4) Write a Python programming to display a bar chart of the popularity of
programming Languages. Select the width of each bar and their positions. Sample
data:
Programming languages: Java, Python, PHP, JavaScript, C#, C++ Popularity: 22.2,
17.6, 8.8, 8, 7.7, 6.7
Output:-
Q5) Write a Python programming to create a pie chart with a title of the popularity of
programming Languages.Make multiple wedges of the pie. Sample data:
Programming languages: Java, Python, PHP, JavaScript, C#, C++ Popularity: 22.2,
17.6, 8.8, 8, 7.7, 6.7
Output:-
Q6) Write a Python program to draw a scatter plot comparing two subject
marks of Mathematics and Science. Use marks of 10 students. Sample data: Test
Data: math_marks = [88, 92, 80, 89, 100, 80, 60, 100, 80, 34]
science_marks = [35, 79, 79, 48, 100, 88, 32, 45, 20, 30] marks_range = [10, 20,
30, 40, 50, 60, 70, 80, 90, 100]
Output:-