0% found this document useful (0 votes)
440 views

DVPY Lab

Uploaded by

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

DVPY Lab

Uploaded by

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

[Document title]

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

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


m2 = int(input("Enter marks for test2 : "))
m3 = int(input("Enter marks for test3 : "))
if m1 <= m2 and m1 <= m3:
avgMarks = (m2+m3)/2
elif m2 <= m1 and m2 <= m3:
avgMarks = (m1+m3)/2
elif m3 <= m1 and m2 <= m2:

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.

val = int(input("Enter a value : "))


str_val = str(val)
if str_val == str_val[::-1]:
print("Palindrome")
else:
print("Not Palindrome")

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))

num=int(input("Enter the number\n"))


if num>0:
res=Fibonacci(num)
print("Fibonacci of ", num ,"is",res)
else:
print("Error in the input")

Output
Enter the number 5
Fibonacci of 5 is 3

Enter the number -9


Error in input

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]

bin=input("Enter the Binary Number")


print("Binary to Decimal is ",Bin2dec(bin))
oct=input("Enter the octal Number")
print("Octal to Decimal is",oct2hex(oct))

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

print("This sentence has\n")


print("words: ", len(wordcont),"\n" "digits",digCnt, )
print("upper case letters",upCnt, "\n" "lower case letters ",loCnt)
Output
Enter a sentence : Hello RNSIT, 2001 &
This sentence has
words: 4
digits 4
upper case letters 6
lower case letters 4

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]

5 a) Write a Python program to Demonstrate how to Draw a Histogram Plot using


Matplotlib.

from matplotlib import pyplot as plt

import numpy as np

a = np.array([22, 87, 5, 43, 56, 73, 55, 54, 11, 20, 51, 5, 79, 31,27])

fig, ax = plt.subplots(figsize =(10, 7))

ax.hist(a, bins = [0, 25, 50, 75, 100])

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')

2. Python program to do arithmetical operations


# Store input numbers:
num1 = input('Enter first number: ')
num2 = input('Enter second number: ')

# Add two numbers


sum = float(num1) + float(num2)
# Subtract two numbers
min = float(num1) - float(num2)
# Multiply two numbers
mul = float(num1) * float(num2)
#Divide two numbers
div = float(num1) / float(num2)
# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))

# Display the subtraction


print('The subtraction of {0} and {1} is {2}'.format(num1, num2, min))
# Display the multiplication
print('The multiplication of {0} and {1} is {2}'.format(num1, num2, mul))
# Display the division
print('The division of {0} and {1} is {2}'.format(num1, num2, div))

3. Python program to find the area of a triangle


a=5
b=6
c=7
# Uncomment below to take inputs from the user
# a = float(input('Enter first side: '))
# b = float(input('Enter second side: '))
# c = float(input('Enter third side: '))
# calculate the semi-perimeter
s = (a + b + c) / 2
# calculate the area
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)

4. Python program to swap two variables


#swapping of 2 numbers
p=int(input("enter the value of a"))
q=int(input("enter the value of b"))
print('Before Swapping the value of p=',p,'and q=',q)
temp=p
p=q
q=temp
print('After swapping the value of p=',p,'and q=',q)

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)

6. WAP to find Factorial of a number using for loop


fact=1
n=int(input("enter the value of n to find factorial of a given number"))
for i in range(1,n+1) :
fact=fact*i
print(fact)

7. WAP to find Factorial of a number using while loop


fact=1
i=1
n=int(input("enter the value of n to find factorial of a given number"))
while i<=n :
fact=fact*i
i=i+1
print(fact)

8. WAP to find fibonacci series using Iterative:


n = int(input("How many terms? "))
n1, n2 = 0, 1
count = 0
if n <= 0:
print("Please enter a positive integer")
elif n == 1:
print("Fibonacci sequence upto",n,":")
print(n1)
else:
print("Fibonacci sequence:")
while count < n:
print(n1)
next = n1 + n2
n1 = n2
n2 = next
count += 1

9. WAP to find fibonacci series using recursion:


def fib(n):
if n <= 1:
return n
else:
return(fib(n-1) + fib(n-2))

nterms = int(input("How many terms? "))


if nterms<= 0:
print("Plese enter a positive integer")
else:
print("Fibonacci sequence:")

Page | 13
Dept. of CSE
Data Visualization with Python (BCS358D)

[Document title]
for i in range(nterms):
print(fib(i))

10 . WAP to find largest among three numbers, input by user


n1=int(input("enter first number"))
n2=int(input("enter sec number"))
n3=int(input("enter third number"))

if n1>n2 and n1>n3 :


print("n1 is larger")
elif n2>n3 and n2>n1 :
print("n2 is larger")
else :
print("n3 is larger")

11. WAP to print first ten programs using for loop .


for i in range(1,11) :
print(i)

12. WAP to print first ten programs using while loop.


I=1
while i<=10:
print(i)
i=i+1

13. WAP to check whether a person is eligible for voting.


age=input()
type(age)
x=int(age)
if x>18 :
print("eligible")
else :
print("not ")

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")

15.WAP to find factorial of given number using for loop.


fact=1
for i in range(1,6) :
fact*=i
print(fact)

16.WAP to find factorial of given number using while loop.


fact=1
i=1

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)

17. WAP to find factorial of given number using functions.


def fact(n) :
fact=1
i=1
while i<=n :
fact*=i
i=i+1
return fact
#print(fact)
n=int(input("enter the number to find factoral of a given number"))
print(fact(n))

18.WAP to find gcd of 2 numbers.


def gcd(a,b):
if b==0:
return a
else :
return gcd(b,a%b)
n1=int(input("enter the first number"))
n2=int(input("enter the second number"))
print(gcd(n1,n2))

19. Python program to generate a random number


20. Python program to convert kilometers to miles.
21. Python program to convert Celsius to Fahrenheit
22. Python program to display calendar
23. Python Program to Check if a Number is Positive, Negative or Zero
24. Python Program to Check if a Number is Odd or Even
25. Python Program to Check Leap Year
26. Python Program to Check Prime Number
27. Python Program to Print all Prime Numbers in an Interval
28. Python Program to Find the Factorial of a Number
29. Python Program to Display the multiplication Table
30. Python Program to Print the Fibonacci sequence
31.Python Program to Check Armstrong Number
32.Python Program to Find Armstrong Number in an Interval

Python Additional Programs


1. Python program to print "Hello Python"
2. Python program to do arithmetical operations
3. Python program to find the area of a triangle
4. Python program to solve quadratic equation
5. Python program to swap two variables

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy