Manual Vtu
Manual Vtu
Manual - VTU
BCS358D
January 5, 2024
1 1a
"""
a) Write a python program to find the best of two test average
marks out of three test's marks accepted from the user.
s = input('Enter b: ')
b = int(s)
s = input('Enter c: ')
c = int(s)
max = a+b
avg = max/2
print(avg)
2 1b
"""
b) Develop a Python program to check whether a given number is
palindrome or not and also count the number of occurrences of each
digit in the input number.
"""
s = #input('Enter number : ')
if s[:] == s[::-1]:
print('Palindrome')
else:
print('Not a palindrome')
d = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for c in s:
i = int(c)
d[i] = d[i] + 1
print(d)
3 2a
"""
Defined as a function F as Fn = Fn-1 + Fn-2. Write a Python
program which accepts a value for N (where N >0) as input and pass
this value to the function. Display suitable error message if the
condition for input value is not followed.
"""
def f(n) :
a, b = 0, 1
for i in range(n) :
c = a+b
a, b = b, c
return c
s = input("Enter n: ")
n = int(s)
if n > 0:
rv = f(n)
print(rv)
else:
print("n = ", n, "Enter n > 1")
RUN
Enter n: 6
13
4 2b
"""
Develop a python program to convert binary to decimal,
octal to hexadecimal using functions.
"""
s = input('Enter binary number: ')
n = int(s, 2)
print(n)
n = hex(n)
print(n)
RUN
5 3a
"""
a) Write a Python program that accepts a sentence and find the number
of words, digits, uppercase letters and lowercase letters.
"""
s = input("Enter s: ")
d = {}
for c in s:
if c.isspace(): # Assumption is words are separated by a single space.
d['W'] = d.get('W', 1) + 1
if c.isdigit():
d['D'] = d.get('D', 0) + 1
if c.isupper():
d['U'] = d.get('U', 0) + 1
if c.islower():
d['L'] = d.get('L', 0) + 1
print(d)
RUN
6 3b
"""
b) Write a Python program to find the string similarity between
two given strings
"""
# Longest contiguous matching subsequence (LCS)
import difflib
rv = difflib.SequenceMatcher(a=s1, b=s2)
RUN
7 4a
"""
Write a Python program to Demonstrate how to Draw a Bar Plot
using Matplotlib
"""
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('./src/lifespan.csv')
# Plot area
plt.figure(figsize=(10, 4))
# Bar plot 1
plt.bar(df['Animal'], df['Lifespan'], width=.75, label="blue")
# legend
plt.legend(loc="best")
# Display
plt.show()
RESULT
8 4b
"""
Write a Python program to Demonstrate how to Draw a Scatter Plot
using Matplotlib.
"""
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('./src/lifespan.csv')
# Plot area
plt.figure(figsize=(10, 4))
# legend
plt.legend(loc="best")
# Display
plt.show()
RESULT
9 5a
"""
Write a Python program to Demonstrate how to Draw a Scatter Plot
using Matplotlib.
"""
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('./src/lifespan.csv')
# Plot area
plt.figure(figsize=(10, 4))
# legend
plt.legend(loc="best")
# Display
plt.show()
RESULT
10 5b
"""
Write a Python program to Demonstrate how to Draw a Pie Chart
using Matplotlib.
"""
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('./src/lifespan.csv')
# Plot area
plt.figure(figsize=(10, 4))
# legend
plt.legend(loc="best")
# Display
plt.show()
11 6a
"""
Write a Python program to illustrate Linear Plotting using
Matplotlib.
"""
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('./src/lifespan.csv')
# Plot area
plt.figure(figsize=(10, 4))
# grid
plt.grid()
# legend
plt.legend(loc="best")
# Display
plt.show()
12 6b
"""
Write a Python program to illustrate Linear Plotting using
Matplotlib.
"""
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('./src/lifespan.csv')
# Plot area
plt.figure(figsize=(10, 4))
# grid
plt.grid()
# legend
plt.legend(loc="best")
# Display
plt.show()
13 7
"""
Write a Python program which explains uses of customizing seaborn
plots with Aesthetic functions.
"""
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style='white')
df = pd.read_csv('./src/lifespan.csv')
# Plot area
# plt.figure(figsize=(10, 4)) not required
sns.set(style="dark")
sns.despine()
# grid
# plt.grid() not required
# legend
plt.legend(loc="best")
# Display
plt.show()
14 8
Write a Python program to explain working with bokeh line graph using Annota-
tions and Legends. a) Write a Python program for plotting different types of plots
using Bokeh.
import numpy as np
import pandas as pd
from bokeh.plotting import figure, show
df = pd.read_csv('./src/lifespan.csv')
# Output plot
show(plot)
15 9
"""
Write a Paython program to draw 3D Plots using Plotly Libraries.
"""
import plotly.graph_objects as go
import numpy as np
import pandas as pd
from bokeh.plotting import figure, show
df = pd.read_csv('./src/lifespan.csv')
print(df)
fig.show()