0% found this document useful (0 votes)
7 views13 pages

Dvpy Lab Exam

T

Uploaded by

leomax42097
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views13 pages

Dvpy Lab Exam

T

Uploaded by

leomax42097
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

program 1.

m1=int(input("Enter marks for test1:"))


m2=int(input("Enter marks for test2:"))
m3=int(input("Enter marks for test3:"))
avg=float()
if(m1>m2):
if(m2>m3):
t=m1+m2
else:
t=m1+m3
elif(m1>m3):
t=m1+m2
else:
t=m2+m3
avg=t/2
print("Average marks:",avg)

Enter marks for test1:23


Enter marks for test2:24
Enter marks for test3:12
Average marks: 23.5

program 1.b

v=int(input("enter some numbers:"))


sv=str(v)
print("palindrome" if(sv==sv[::-1]) else "not a plaindrome")
for i in range(10):
c=sv.count(str(i))
if(c>0):
print(i," appears",c,"times")

enter some numbers:3435543


not a plaindrome
3 appears 3 times
4 appears 2 times
5 appears 2 times

program 2.a

def f(n):
if n==1:
return 0
if n==2:
return 1
return f(n-1)+f(n-2)
n=int(input("enter a number:"))
print("f(",n,")=",f(n))
enter a number:5
f( 5 )= 3

prgram 2.b

def b_d(bstr):
dnum=0
bstr=bstr[::-1]
for i in range(len(bstr)):
if bstr[i]=='1':
dnum+=2**i
return dnum
def o_h(ostr):
ostr=int(ostr,8)
return hex(ostr)[2:]
while True:
print("1.Binary to Decimal")
print("2.octal to Hexadecimal")
print("3.to exit")
c=int(input("enter your choice:"))
if c==1:
bstr=input("enter a binary number:")
print("decimal=",b_d(bstr))
elif c==2:
ostr=input("enter a octal number:")
print("hexadecimal=",o_h(ostr))
elif c==3:
break
else:
print("invalid choice")

1.Binary to Decimal
2.octal to Hexadecimal
3.to exit
enter your choice:1
enter a binary number:100101
decimal= 37
1.Binary to Decimal
2.octal to Hexadecimal
3.to exit
enter your choice:2
enter a octal number:2356
hexadecimal= 4ee
1.Binary to Decimal
2.octal to Hexadecimal
3.to exit
enter your choice:3

program 3.a
s=input("enter a sentence:")
wl=len(s.split())
dc=uc=lc=0
for w in s:
if '0'<=w<='9':
dc+=1
elif 'A'<=w<='Z':
uc+=1
elif 'a'<='z':
lc+=1
print("count",wl)
print("digits=",dc)
print("upper case letters=",uc)
print("lower case letters=",lc)

enter a sentence:This Sentence Contains 234letters


count 4
digits= 3
upper case letters= 3
lower case letters= 27

program 3.b

s1=input("enter first string:")


s2=input("enter second string:")
if len(s1)>len(s2):
s=len(s2)
l=len(s1)
else:
s=len(s1)
l=len(s2)
c=0
for i in range(s):
if s1[i]==s2[i]:
c+=1
print("similarity b/w two strings : ",c/l)

enter first string:this is a first sentence


enter second string:this is a second sentence
similarity b/w two strings : 0.4

program 4.a

import matplotlib.pyplot as p
c=['cat1','cat2','cat3','cat4']
v=[23,45,67,89]
p.bar(c,v,color='red')
p.xlabel("categories")
p.ylabel("values")
p.title("bar plot")
p.show()

program 4.b

import matplotlib.pyplot as p
x=[1,2,3,4,5,6,7,8]
y=[8,7,6,5,4,3,2,1]
p.scatter(x,y,color='yellow',marker='o',alpha=0.5,label='scatter
points')
p.xlabel("x-axis")
p.ylabel("y-axis")
p.title("scatter plot")
p.legend()
p.show()
program 5.a

import matplotlib.pyplot as p
d=[1,2,12,13,1,42,135,78,34,56,89,87,54,23,56,99,9,6,5,90]
p.hist(d,bins=5,color='green',edgecolor='black')
p.xlabel("data")
p.ylabel("frequency")
p.title("histogram")
p.grid(True)
p.show()
program 5.b

import matplotlib.pyplot as p
l=['cat1','cat2','cat3','cat4']
v=[15,15,45,25]#total should be 100
p.pie(v,labels=l,autopct='%1.1f%%')
p.show()
program 6.a

import matplotlib.pyplot as p
x=[1,2,3,4,5,6,7,8]
y=[8,7,6,5,4,3,2,1]
p.figure(figsize=(10,5))
p.plot(x,y,marker='o',linestyle='-',color='red')
p.xlabel("x-axis")
p.ylabel("y-axis")
p.title("line plot")
p.grid(True)
p.show()
program 6.b

import matplotlib.pyplot as p
x=[1,2,3,4,5,6,7,8]
y1=[8,7,6,5,4,3,2,1]
y2=[2,4,6,8,10,12,14,16]
p.figure(figsize=(10,5))
p.plot(x,y1,marker='o',linestyle='-',color='red',label='line1')
p.plot(x,y2,marker='s',linestyle='-',color='blue',label='line2')
p.xlabel("x-axis")
p.ylabel("y-axis")
p.title("line plot")
p.legend()
p.grid(True)
p.show()
program 7

import seaborn as s
import matplotlib.pyplot as p
a=[1,2,3,4,5]
b=[9,8,7,6,5]
s.set(style='whitegrid')
p.figure(figsize=(8,6))
s.scatterplot(x=a,y=b,color='red',marker='s',s=100,label='scatter
plot')
p.xlabel("x-axis")
p.ylabel("y-axis")
p.title("customised using seaborn")
p.legend()
p.show()
program 8.a

from bokeh.plotting import figure, show


from bokeh.models import Label, Legend

x = [1, 2, 3, 4, 5]
y1, y2 = [2, 4, 6, 8, 10], [1, 3, 5, 7, 9]

p = figure(title="Bokeh Line Graph", x_axis_label="X-axis",


y_axis_label="Y-axis")

line1 = p.line(x, y1, legend_label="Line 1", line_width=2,


line_color="blue")
line2 = p.line(x, y2, legend_label="Line 2", line_width=2,
line_color="red")

p.add_layout(Label(x=3, y=8, text="Annotation 1",


text_font_size="12pt", text_color="blue"))
p.add_layout(Label(x=2.5, y=3, text="Annotation 2",
text_font_size="12pt", text_color="red"))
show(p)

output will be avail in new tab.

program 8.b

from bokeh.plotting import figure, show


from bokeh.layouts import gridplot
import numpy as np

x = np.linspace(0, 4 * np.pi, 100)


y = np.sin(x)
categories = ['A', 'B', 'C', 'D']
values = [4, 7, 1, 2]
data = np.random.normal(0, 1, 1000)

p1 = figure(title="Line Plot", width=400, height=300)


p1.line(x, y, line_width=2, color="blue")

p2 = figure(title="Scatter Plot", width=400, height=300)


p2.scatter(x, y, size=6, color="red")

p3 = figure(x_range=categories, title="Bar Plot", width=400,


height=300)
p3.vbar(x=categories, top=values, width=0.5, color="green")

p4 = figure(title="Histogram", width=400, height=300)


hist, edges = np.histogram(data, bins=20)
p4.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:],
fill_color="purple", line_color="black")

show(gridplot([[p1, p2], [p3, p4]]))

output will be avail in new tab.

program 9

import plotly.graph_objects as go
import numpy as np

x =np.linspace(-5, 5, 100)
y =np.linspace(-5, 5, 100)

X, Y=np.meshgrid(x, y)
Z =np.sin(np.sqrt(X**2 + Y**2))

fig = go.Figure(data=[go.Surface(z=Z, x=X, y=Y)])

fig.update_layout(title="3D Surface Plot",scene=dict(xaxis_title="X-


axis",yaxis_title="Y-axis",zaxis_title="Z-axis",))

fig.show()

program 10.a

import plotly.graph_objects as go
import pandas as pd

data = {
'Date': pd.date_range(start='2023-01-01', periods=10, freq='D'),
'Value': [10, 12, 15, 20, 18, 22, 25, 28, 30, 32] }

df = pd.DataFrame(data)

fig = go.Figure()
fig.add_trace(go.Scatter(x=df['Date'], y=df['Value'],
mode='lines+markers', name='Time Series'))

fig.update_layout(
title="Time Series Line Chart",
xaxis_title="Date",
yaxis_title="Value",
xaxis=dict(
rangeselector=dict(
buttons=list([
dict(count=7, label="1w", step="day", stepmode="backward"),
dict(count=1, label="1m", step="month", stepmode="backward"),
dict(count=6, label="6m", step="month", stepmode="backward"),
dict(step="all")]
)),rangeslider=dict(visible=True),type="date")
)
fig.show()

program 10.b

import plotly.graph_objects as go

data = {
'State': ['Delhi', 'Maharashtra', 'Tamil Nadu', 'Karnataka',
'Kerala'],
'Latitude': [28.6139, 19.7515, 11.1271, 15.3173, 10.8505],
'Longitude': [77.2090, 75.7139, 78.6569, 75.7139, 76.2711],
'Value': [100, 200, 300, 400, 500]
}

fig = go.Figure()
for i in range(len(data['State'])):
fig.add_trace(go.Scattergeo(
lon=[data['Longitude'][i]], lat=[data['Latitude'][i]],
text=f"{data['State'][i]}<br>Value: {data['Value'][i]}",
mode='markers',
marker=dict(size=10, opacity=0.7, color=data['Value'][i],
colorscale='Viridis',
colorbar=dict(title='Value')),
name=data['State'][i]
))

fig.update_geos(scope='asia', showcoastlines=True,
coastlinecolor="Black", showland=True, landcolor="lightgray")
fig.update_layout(title='Indian States Map')
fig.show()

You might also like