DVPY Lab
DVPY Lab
SYLLABUS
Data Visualization with Python(BCS358D)
Course Code BCS358D CIE Marks 50
Number of Contact Hours/Week 0:0:2:0 SEE Marks 50
Total Number of Lab Contact Hours 24 Exam Hours 03
Credits –1
Descriptions(if any):
Programs List:
a) Write a python program to find the best of two test average marks out of three test’s marks
accepted from the user.
1.
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.
a) 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
2. if the condition for input value is not followed.
b) Develop a python program to convert binary to decimal, octal to hexadecimal using
functions.
a) Write a Python program that accepts a sentence and find the number of words, digits,
uppercase letters and lowercase letters.
b) Write a Python program to find the string similarity between two given strings
Sample Output: Sample Output:
3 Original string: Original string:
Python Exercises Python Exercises
Python Exercises Python Exercise
Similarity between two said strings: Similarity between two said strings:
1.0 0.967741935483871
a)Write a Python program to Demonstrate how to Draw a Bar Plot using Matplotlib.
4
b) Write a Python program to Demonstrate how to Draw a Scatter Plot using Matplotlib.
a) Write a Python program to Demonstrate how to Draw a Histogram Plot using Matplotlib.
5.
b) Write a Python program to Demonstrate how to Draw a Pie Chart using Matplotlib
a) Write a Python program to illustrate Linear Plotting using Matplotlib.
6 b) Write a Python program to illustrate liner plotting with line formatting using Matplotlib.
1.a )Write a python program to find the best of two test average marks out of three test’s marks
accepted from the use
Page | 1
Data Visualization with Python (BCS358D)
[Document title]
avgMarks = (m1+m2)/2
print("Average of best two test marks out of three test’s marks is", avgMarks);
OR
m1=int(input("Enter the test1 Marks"))
m2=int(input("Enter the test2 Marks"))
m3=int(input("Enter the test3 Marks"))
L1=[]
L1.append(m1)
L1.append(m2)
L1.append(m3)
L1.sort()
print(L1)
Avg=(L1[1]+L1[2])/2
print("Average of best two test marks out of three test’s marks is ",Avg)
output
Enter the test1 Marks 25
Enter the test2 Marks 25
Enter the test3 Marks 12
[12, 25, 25]
Average of Best of two Test is 25.0
OR
m1=int(input("Enter the test1 Marks"))
m2=int(input("Enter the test2 Marks"))
m3=int(input("Enter the test3 Marks"))
Minimum=min(m1,m2,m3)
sum=m1+m2+m3-Minimum
Avg=sum/2
print("Average of best two test marks out of three test’s marks is ",Avg)
1.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.
for i in range(10):
if str_val.count(str(i)) > 0:
print(str(i),"appears", str_val.count(str(i)), "times");
OR
Page | 2
Dept. of CSE
Data Visualization with Python (BCS358D)
[Document title]
num=input("Enter the Number")
rev=num
if (rev==rev[::-1]):
print("The Number is Palindrome", num)
else:
print("The Number is not Palindrome", num)
for i in set(num):
print(i, "appears", num.count(str(i)),"times")
output
Enter the Number12321
The Number is Palindrome 12321
1 appears 2 times
3 appears 1 times
2 appears 2 times
Page | 3
Dept. of CSE
Data Visualization with Python (BCS358D)
[Document title]
2. a) 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 Fibonacci(n):
if n==1:
return 0
elif n==2:
return 1
else:
return (Fibonacci(n-1)+Fibonacci(n-2))
Output
Enter the number 5
Fibonacci of 5 is 3
2.b) Develop a python program to convert binary to decimal, octal to hexadecimal using
functions.
def Bin2dec(bin):
l=len(bin)
dec=0
for i in range(l):
dec+=int(bin[i])*(2**(l-i-1))
return dec
def oct2hex(oct):
l=len(oct)
dec=0
for i in range(l):
dec+=int(oct[i])*(8**(l-i-1))
hexa=['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F']
octhex=' '
while dec>0:
rem=dec%16
octhex=hexa[rem]+octhex
dec=dec//16
return octhex
Page | 4
Dept. of CSE
Data Visualization with Python (BCS358D)
[Document title]
OUTPUT:
Enter the Binary Number1011
Binary to Decimal is 11
Enter the octal Number12
Octal to Decimal is A
Page | 5
Dept. of CSE
Data Visualization with Python (BCS358D)
[Document title]
3. a) Write a Python program that accepts a sentence and find the number of words, digits,
uppercase letters and lowercase letters.
sentence = input("Enter a sentence : ")
digCnt = upCnt = loCnt =wordcnt=0
wordcont=sentence.split()
for ch in sentence:
if ch>='0' and ch<='9':
digCnt += 1
if ch>='A'and ch<='Z':
upCnt += 1
if ch>='a' and ch<='z':
loCnt += 1
3.b) Write a Python program to find the string similarity between two given strings
def compare(s,p):
count=0
n=min(len(s),len(p))
for i in range(n):
if s[i]==p[i]:
count+=1
return count
s1 = input("Enter String 1 \n")
s2 = input("Enter String 2 \n")
mx=max(len(s1),len(s2))
count=compare(s1,s2)
similarity=count/mx*100
print ("Total number letter matched is",count)
print("simirality between two string is",similarity)
Output
Enter String 1
rnsit
Enter String 2
rnsit
Total number letter matched is 5
simirality between two string is 100.0
Enter String 1
welcome
Enter String 2
rnsit
Page | 6
Dept. of CSE
Data Visualization with Python (BCS358D)
[Document title]
Total number letter matched is 0
simirality between two string is 0.0
4.a ) Write a Python program to Demonstrate how to Draw a Bar Plot using Matplotlib.
import matplotlib.pyplot as plt
plt.bar([1,3,5,7,9],[5,2,7,8,2], label="Data 1")
plt.legend()
# The following commands add labels to our figure.
plt.xlabel('X values')
plt.ylabel('Height')
plt.title('Vertical Bar chart')
plt.show()
OUTPUT
Or
import matplotlib.pyplot as plt
plt.barh(["Cats","Dogs","Goldfish","Snakes","Turtles"],
[5,2,7,8,2], align='center', label="Data 1")
plt.legend()
plt.ylabel('Pets')
plt.xlabel('Popularity')
plt.title('Popularity of pets in the neighbourhood')
plt.show()
OUTPUT
Page | 7
Dept. of CSE
[Document title]
Page | 8
[Document title]
import numpy as np
a = np.array([22, 87, 5, 43, 56, 73, 55, 54, 11, 20, 51, 5, 79, 31,27])
plt.show()
OUTPUT:
Page | 9
[Document title]
OUTPUT:
Page | 10
[Document title]
marks=[]
for i in range(0,len(studentsusn)):
marks.append(random.randint(0, 101))
plt.xlabel("Students")
plt.ylabel("Marks")
plt.title("CLASS RECORDS")
plt.plot(studentsusn,marks, color = 'green', linestyle = 'solid', marker = 'o', markerfacecolor =
'red', markersize = 15)
OUTPUT
Page | 11
Data Visualization with Python (BCS358D)
[Document title]
Sample Programs
1. Python program to print "Hello Python"
print ('Hello Python')
5. Python program to find the sum and average of natural numbers up to n where n is provided by
user.
Page | 12
Dept. of CSE
Data Visualization with Python (BCS358D)
[Document title]
n=int(input("Enter upto which number you want sum and average"))
sum=0
for i in range(0,n+1):
sum=sum+i
avg=sum/n
print("Result of sum is",sum)
print("Result of Average",avg)
Page | 13
Dept. of CSE
Data Visualization with Python (BCS358D)
[Document title]
for i in range(nterms):
print(fib(i))
14. WAP to print grades obtained by the students and print the appropriate message.
marks=input()
type(marks)
x=int(marks)
if x>=90 and x<100:
print('distinction')
elif x>=80 and x<=90:
print("first")
else :
print("fail")
Page | 14
Dept. of CSE
Data Visualization with Python (BCS358D)
[Document title]
n=int(input())
while i<=n:
fact=fact*i
i=i+1
print(fact)
Page | 15
Dept. of CSE
[Document title]
6. Python program to generate a random number
7. Python program to convert kilometers to miles
8. Python program to convert Celsius to Fahrenheit
9. Python program to display calendar
10. Python Program to Check if a Number is Positive, Negative or Zero
11. Python Program to Check if a Number is Odd or Even
12. Python Program to Check Leap Year
13. Python Program to Check Prime Number
14. Python Program to Print all Prime Numbers in an Interval
15. Python Program to Find the Factorial of a Number
16. Python Program to Display the multiplication Table
17. Python Program to Print the Fibonacci sequence
18. Python Program to Check Armstrong Number
19. Python Program to Find Armstrong Number in an Interval
20. Python Program to Find the Sum of Natural Numbers
21. Python Function Programs
22. Python Program to Find LCM
23. Python Program to Find HCF
24. Python Program to Convert Decimal to Binary, Octal and Hexadecimal
25. Python Program To Find ASCII value of a character
26. Python Program to Make a Simple Calculator
27. Python Program to Display Calendar
28. Python Program to Display Fibonacci Sequence Using Recursion
29. Python Program to Find Factorial of Number Using Recursion
30. Python Number Programs
31. Python program to check if the given number is a Disarium Number
32. Python program to print all disarium numbers between 1 to 100
33. Python program to check if the given number is Happy Number
34. Python program to print all happy numbers between 1 and 100
35. Python program to determine whether the given number is a Harshad Number
36. Python program to print all pronic numbers between 1 and 100
37. Python Array Programs
38. Python program to copy all elements of one array into another array
39. Python program to find the frequency of each element in the array
40. Python program to left rotate the elements of an array
41. Python program to print the duplicate elements of an array
42. Python program to print the elements of an array
43. Python program to print the elements of an array in reverse order
44. Python program to print the elements of an array present on even position
45. Python program to print the elements of an array present on odd position
46. Python program to print the largest element in an array
47. Python program to print the smallest element in an array
48. Python program to print the number of elements present in an array
49. Python program to print the sum of all elements in an array
50. Python program to right rotate the elements of an array
51. Python program to sort the elements of an array in ascending order
Page | 16
[Document title]
52. Python program to sort the elements of an array in descending order
Page | 17
[Document title]
Viva Questions:
1. What it the syntax of print function?
2. What is the usage of input function?
3. Define a variable.
4. What is type conversion?
5. Mention the data types in Python
6. What are the attributes of the complex datatype?
7. Mention a few escape sequences.
8. Define an expression
9. What is the usage of ** operator in Python?
10. Give the syntax of if else statement.
11. Give the syntax of for statement.
12. How is range function used in for?
13. Give the syntax of while statement.
14. What are multi way if statements?
15. How is random numbers generated?
16. Define a function.
17. Give the syntax of function.
18. What are the types of arguments in function.?
19. What is a recursive function?
20. What are anonymous functions?
21. What are default arguments?
22. What are variable length arguments?
23. What are keyword arguments?
24. Mention the use of map().
25. Mention the use of filter().
26. Mention the use of reduce().
27. Define a string.
28. How is string slicing done?
29. What is the usage of repetition operator?
30. How is string concatenation done using + operator>
31. Mention some string methods
32. How is length of a string found?
33. How is a string converted to its upper case?
34. `Differentiate isalpha() and isdigit().
35. What is the use of split()?
36. Define a file.
37. Give the syntax for opening a file.
38. Give the syntax for closing a file.
39. How is reading of file done?
40. How is writing of file done?
41. What is a list?
Page | 18
[Document title]
42. Lists are mutable-Justify.
43. How is a list created?
44. How can a list be sorted?
45. How are elements appended to the list?
46. How is insert() used in list?
47. What is the usage of pop() in list?
48. Define a tuple.
49. Are tuples mutable or immutable?
50. Mention the use of return statement.
51. What is a Boolean function?
52. How is main function defined?
53. What is a dictionary?
54. How are tuples created?
55. How is a dictionary created?
56. How to print the keys of a dictionary?
57. How to print the values of a dictionary?
58. How is del statement used?
59. Can tuple elements be deleted?
60. What is Python interpreter?
61. Why is Python called an interpreted language?
62. Mention some features of Python
63. What is Python IDLE?
64. Mention some rules for naming an identifier in Python.
65. Give points about Python Numbers.
66. What is bool datatype?
67. Give examples of mathematical functions.
68. What is string formatting operator?
69. Mention about membership operators in Python.
70. How is expression evaluated in Python?
71. What are the loop control statements in Python?
72. What is the use of break statement?
73. What is the use of continue statement?
74. What is the use of pass statement?
75. What is assert statement?
76. Differentiate fruitful function s and void functions.
77. What are required arguments ?
78. Differentiate pass by value and pass by reference.
79. Mention few advantages of function.
80. How is lambda function used?
81. What is a local variable?
82. What are global variables?
83. What are Python decorators?
84. Are strings mutable or immutable?
85. What is join()?
Page | 19
[Document title]
86. What is replace() method?
87. What is list comprehension?
88. Define multidimensional list.
89. How to create lists using range()?
90. What is swapcase() method?
91. What is linear search?
92. How is binary search done?
93. How is merge sort performed?
94. What is sorting?
95. How is insertion sort done?
96. How is selection sort done?
97. What are command line arguments?
98. Name some built in functions with dictionary.
99. What is an exception?
100. How is exception handled in python?
Page | 20