MSBTE PWP 22616 Practical exam Question 2024-25
1 Write a program to find the square root of a number.
import math
# square-root of a number
A = int(input("Enter A number = "))
sqr = math.sqrt(A)
print("The Square-Root of ",A," = ",sqr)
2. Write a program to convert bits to Megabytes, Gigabytes and Terabytes.
bit = int(input("Enter the bit: "))
# Conversions
byte = bit / 8
kb = byte / 1024
mb = kb / 1024
gb = mb / 1024
tb = gb / 1024
# Printing results with 6 decimal places
print(f"{bit} bits in Megabytes (MB) = {mb:.6f}")
print(f"{bit} bits in Gigabytes (GB) = {gb:.6f}")
print(f"{bit} bits in Terabytes (TB) = {tb:.6f}")
3. Write a program to swap the value of two variables.
a = input("Enter value for a: ")
b = input("Enter value for b: ")
print("Before swapping: a = ",a," b = ",b)
# Swapping using temp
temp = a
a=b
b = temp
print("After swapping: a = ",a," b = ",b)
4. Write a program to calculate surface volume and area of a cylinder.
import math
# Input
radius = float(input("Enter the radius of the cylinder: "))
height = float(input("Enter the height of the cylinder: "))
# Calculations
surface_volume = math.pi * radius**2 * height
area = 2 * math.pi * radius * (radius + height)
# Output
print("Volume of the cylinder = ",surface_volume ,"cubic units")
print("Surface area of the cylinder: ",area, "square units")
5. Write a program to check if the input year is a leap year of not.
year = int(input("Enter the year = "))
if year%4==0:
print(year," is a Leap year ")
else:
print(year," is not a Leap year ")
6. Write a program to check if a Number is Positive, Negative or Zero
num = int(input("enter the Any Whole number = "))
if num==0:
print("The number is Zero [0]")
if num<0:
print("The number is Negative [-]")
if num>0:
print("The number is Positive [+]")
7. Write a program that takes the marks of 5 subjects and displays the grades
print("Enter the Marks of Subject Given Below : ")
py = int(input("Python = "))
mad = int(input("Mobile Application Development = "))
php = int(input("PHP = "))
eti = int(input("ETI = "))
man = int(input("MAN = "))
avg=(py+mad+php+eti+man)/5
print("Average Marks = ",avg)
if avg>=80:
print("..A..")
elif avg>=60:
print("..B..")
elif avg>=40:
print("..C..")
elif avg>=35:
print("..D..")
else:
print("..Fail..")
8. Write a python program to find Fibonacci series for given number.
n = int(input("Enter number of terms: "))
a=0
b=1
print("Fibonacci Series:")
for i in range(n):
print(a, end=" ")
c=a+b
a=b
b=c
9. Write a python program to find sum of four digit number.
num = int(input("Enter a 4-digit number: "))
d1 = num // 1000 #thousand
d2 = (num // 100) % 10#hundred
d3 = (num // 10) % 10#tens
d4 = num % 10#once
total = d1 + d2 + d3 + d4
print("Sum of digits =", total)
10. Write a Python program to find common items from two lists
list1 = [1, 2, 3, 4]
list2 = [3, 4, 5, 6]
common = list(set(list1) & set(list2))
print("Common items:", common)
11. Create a tuple and find the minimum and maximum number from it.
#creating a tuple
t1=(22,45,7,8,56,72)
ma = max(t1)
mi = min(t1)
print("The Maximum Number From te tuple = ",ma)
print("The Minimum Number From te tuple = ",mi)
12. Write a Python program to find the repeated items of a tuple.
# Define the tuple
my_tuple = (1, 2, 3, 4, 5, 6, 3, 7, 8, 2, 9, 5)
# Find and print repeated items
repeated_items = set(item for item in my_tuple if my_tuple.count(item) > 1)
print("Repeated items in the tuple:", repeated_items)
13. Write a Python script to concatenate following dictionaries to create a new one. Sample
Dictionary: dic1 = {1:10, 2:20} dic2 = {3:30, 4:40} dic3 = {5:50,6:60}
dic1 = {1:10, 2:20}
dic2 = {3:30, 4:40}
dic3 = {5:50,6:60}
#creating a new dictionary
dic4 = {0:0}
#dic4 = {}
#concatenating the dictionary
dic4.update(dic1)
dic4.update(dic2)
dic4.update(dic3)
print("The new Dictionary = ",dic4)
14. Write a Python program to combine two dictionary adding values for common keys.
d1 = {'a': 100, 'b': 200, 'c':300} d2 = {'a': 300, 'b': 200, 'd':400}
d1 = {'a': 100, 'b': 200, 'c':300}
d2 = {'a': 300, 'b': 200, 'd':400}
print(d1)
print(d2)
d3 = {}
d3.update(d1)
d3.update(d2)
print("-------------------------------------------")
for key in d1:
if key in d2:
d3[key] = d1[key]+d2[key]
print("After Combining and Adding Values of Common keys = ",d3)
15. Write a Python program to create two matrices and perform addition, subtraction,
multiplication and division operation on matrix using NumPy.
import numpy as np
# Create two small 2x2 matrices
a = np.array([[10, 20],
[30, 40]])
b = np.array([[5, 6],
[7, 8]])
# Perform operations
print("Matrix A:\n", a)
print("Matrix B:\n", b)
print("\nAddition:\n", a + b)
print("\nSubtraction:\n", a - b)
print("\nMultiplication:\n", a * b) # Element-wise
print("\nDivision:\n", a / b) # Element-wise
16. Write a python program to concatenate two strings using NumPy.
import numpy as np
# Define two strings
str1 = "Hello"
str2 = "World"
# Concatenate using numpy.char.add
result = np.char.add(str1, str2)
print("Concatenated String:", result)
17. Write a Python class to reverse a string word by word.
class ReverseString:
def reverse(self, text):
return ' '.join(text.split()[::-1])
# Take input from the user
user_input = input("Enter a sentence: ")
# Create object and call the method
r = ReverseString()
print("Reversed sentence:", r.reverse(user_input))
18. a Python class named Rectangle constructed from length and width and a method Write
that will compute the area of a rectangle.
class Rectangle:
def __init__(self, length, width):
self.length = length
self.width = width
def area(self):
return self.length * self.width
# Take user input
l = float(input("Enter the length of the rectangle: "))
w = float(input("Enter the width of the rectangle: "))
# Create Rectangle object
rect = Rectangle(l, w)
# Compute and display area
print("Area of the rectangle:", rect.area())
19. Write a Python program to create a class to print the area of a square and a rectangle.
The class has two methods with the same name but different number of parameters. The
method for printing area of rectangle has two parameters which are length and breadth
respectively while the other method for printing area of square has one parameter which is
side of square.
class Square:
def area(self, side):
print("Area of Square:", side * side)
class Rectangle:
def area(self, length, breadth):
print("Area of Rectangle:", length * breadth)
# Create objects
sq = Square()
rect = Rectangle()
# Input for square
s = float(input("Enter the side of the square: "))
sq.area(s)
# Input for rectangle
l = float(input("Enter the length of the rectangle: "))
b = float(input("Enter the breadth of the rectangle: "))
rect.area(l, b)
20. Write a Python program to create a class 'Degree' having a method 'getDegree' that
prints "I got a degree". It has two subclasses namely 'Undergraduate' and Postgraduate'
each having a method with the same name that prints "I am an Undergraduate" and "I am
a Postgraduate" respectively. Call the method by creating an object of each of the three
classes.
#Creating a class Degree
class Degree:
def getDegree(self):
print("I got a Degree")
#Creating sub-class
class Undergraduate:
def getDegree(Degree):
print("I am an Undergradute")
#Creating sub-class
class Postgraduate:
def getDegree(Degree):
print("I am a Postgraduate")
#creating object
A=Degree()
B=Undergraduate()
C=Postgraduate()
A.getDegree()
B.getDegree()
C.getDegree()
21. Write a Python program to create series from array using Panda.
import pandas as pd
import numpy as np
# Create a NumPy array
arr = np.array([10, 20, 30, 40, 50])
# Create a Pandas Series from the array
series = pd.Series(arr)
# Print the Series
print("Pandas Series from NumPy Array:")
print(series)