0% found this document useful (0 votes)
4 views71 pages

Python

The document outlines a series of Python programming exercises aimed at performing various tasks such as printing statements, arithmetic operations, and handling lists, tuples, sets, and dictionaries. Each exercise includes an aim, input/output format, source code, and execution results demonstrating successful test cases. The exercises are designed for educational purposes at Medicaps University, focusing on fundamental programming concepts.

Uploaded by

lipof97134
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)
4 views71 pages

Python

The document outlines a series of Python programming exercises aimed at performing various tasks such as printing statements, arithmetic operations, and handling lists, tuples, sets, and dictionaries. Each exercise includes an aim, input/output format, source code, and execution results demonstrating successful test cases. The exercises are designed for educational purposes at Medicaps University, focusing on fundamental programming concepts.

Uploaded by

lipof97134
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

Date: 2026-02-

Page No: 1
[Link]: 1 Exp. Name: Print Statements
02

Aim:

3 9 3 0 1 0 3 S C 5 2 N E : DI
Write a Python program that stores a user's name in a variable and prints a greeting
message in the format "Hello, <name>".

Input Format:
• A single line containing the user's name as a string.

Output Format:
• A single line greeting the user in the format "Hello, <name>".
Source Code:

[Link]

nahuohC ayviD forP-B_11P_2003SC_5202


a = input()

print("Hello,",a)

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

code tantra
Hello, code tantra

Medicaps University
Test Case - 2

User Output

satya
Hello, satya
Date: 2026-02-
[Link]: 2 Exp. Name: Arithmetic Operations

Page No: 2
02

Aim:
Write a program to perform addition, subtraction, multiplication, division, and integer

3 9 3 0 1 0 3 S C 5 2 N E : DI
division on two numbers.

Input Format:
• Two input lines read two positive integers representing the operands.

Output Format:
• The first line should print the result of addition.
• The second line should print the result of subtraction.
• The third line should print the result of multiplication.
• The fourth line should print the result of division with two decimal places.
• The fifth line should print the result of integer division.

nahuohC ayviD forP-B_11P_2003SC_5202


Constraints:
• The second number will not be zero
Source Code:

[Link]

a = int(input())
b = int(input())

if a<0:
print("No")

if b<=0:
print("No")
Medicaps University

print(a+b)
print(a-b)
print(a*b)
print(f"{a/b:.2f}")
print(a//b)

Execution Results - All test cases have succeeded!


Test Case - 1

Page No: 3
User Output

10
3

3 9 3 0 1 0 3 S C 5 2 N E : DI
13
7
30
3.33
3

Test Case - 2

User Output

20

nahuohC ayviD forP-B_11P_2003SC_5202


4
24
16
80
5.00
5

Medicaps University
Exp. Name: Program to print a message Date: 2026-02-
[Link]: 3

Page No: 4
on the screen 02

Aim:
Write a python program to print a message (Hello, World!) on screen.

3 9 3 0 1 0 3 S C 5 2 N E : DI
Source Code:

[Link]

print("Hello, World!")

Execution Results - All test cases have succeeded!

nahuohC ayviD forP-B_11P_2003SC_5202


Test Case - 1

User Output

Hello, World!

Medicaps University
Date: 2026-02-
[Link]: 4 Exp. Name: Area of Rectangle

Page No: 5
02

Aim:
Write a Python program to calculate the area of a rectangle given its length and width.

3 9 3 0 1 0 3 S C 5 2 N E : DI
Formula:
Area of Rectangle = Length × Width

Input Format:
• First line contains a float value representing the length of the rectangle
• Second line contains a float value representing the width of the rectangle

Output Format:
• Print the area of the rectangle as a float value formatted to 2 decimal places.
Source Code:

nahuohC ayviD forP-B_11P_2003SC_5202


[Link]

a = float(input())
b = float(input())

c = a*b
d = f"{c:.2f}"

print(d)

Execution Results - All test cases have succeeded!

Test Case - 1 Medicaps University

User Output

10.5
5.2
54.60

Test Case - 2

User Output

15
8
120.00

Page No: 6
Test Case - 3

3 9 3 0 1 0 3 S C 5 2 N E : DI
User Output

2.5
3.5
8.75

Test Case - 4

User Output

100

nahuohC ayviD forP-B_11P_2003SC_5202


50
5000.00

Test Case - 5

User Output

7
7
49.00

Medicaps University
Date: 2026-02-
[Link]: 5 Exp. Name: Fahrenheit to Celsius

Page No: 7
02

Aim:
Write a Python program to convert temperature from Fahrenheit to Celsius. Prompt the

3 9 3 0 1 0 3 S C 5 2 N E : DI
user to enter a temperature in Fahrenheit.

Formula: °C = 5/9(°F − 32)

Then, print the temperature in Celsius.

Input Format:
• Input should prompt the user to enter the temperature in Fahrenheit as a floating
point.

Output Format:
• The output should print the temperature in Celsius.

nahuohC ayviD forP-B_11P_2003SC_5202


Note: The Celsius value should be rounded to two decimal places.
Source Code:

[Link]

a = float(input())

b = a-32

c = b*5/9

d = f"{c:.2f}"

print(d)
Medicaps University

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

68.5
20.28
Page No: 8 3 9 3 0 1 0 3 S C 5 2 N E : DI nahuohC ayviD forP-B_11P_2003SC_5202 Medicaps University
Test Case - 2

User Output

37.00
98.6
Date: 2026-02-
[Link]: 6 Exp. Name: List Operations in Python

Page No: 9
09

Aim:
Write a Python program to perform the following operations on a list:

3 9 3 0 1 0 3 S C 5 2 N E : DI
1. Read an integer n representing the number of elements.
2. Read n space-separated integers and create a list. Display the original list.
3. Read an integer representing the element to be inserted and an integer representing
the 0-based position at which it should be inserted. Insert the element into the list and
display the list after insertion.
4. Read an integer representing the element to be deleted. If the element exists, delete it
from the list; otherwise, leave the list unchanged. Display the list after deletion.
5. Traverse the final list and display each element on a new line.

Note:
• Assume that all given positions are valid.

nahuohC ayviD forP-B_11P_2003SC_5202


• Use appropriate list methods for insertion and deletion.
• Refer to the visible test cases for better understanding and strictly match with the
input and output statements.
Source Code:

Medicaps University
[Link]

Page No: 10
n = int(input())

list = [int(x) for x in input().split()]

3 9 3 0 1 0 3 S C 5 2 N E : DI
print("Original List:", list)

a = int(input())
b = int(input())

[Link](b,a)

print("After Insertion:", list)

c = int(input())
if (c in list):

nahuohC ayviD forP-B_11P_2003SC_5202


[Link](c)

print("After Deletion:", list)

print("Traversing List:")
for i in list:
print(i)

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

4 Medicaps University
10 20 30 40
Original List: [10, 20, 30, 40]
25
2
After Insertion: [10, 20, 25, 30, 40]
20
After Deletion: [10, 25, 30, 40]
Traversing List:
10
25
40

Page No: 11
Test Case - 2

User Output

3 9 3 0 1 0 3 S C 5 2 N E : DI
123
Original List: [1, 2, 3]
10
0
After Insertion: [10, 1, 2, 3]
5
After Deletion: [10, 1, 2, 3]
Traversing List:
10

nahuohC ayviD forP-B_11P_2003SC_5202


1
2
3

Medicaps University
Date: 2026-02-
[Link]: 7 Exp. Name: Tuple and Set Operations

Page No: 12
16

Aim:
Write a Python program to perform the following operations on Tuple and Set data types.

3 9 3 0 1 0 3 S C 5 2 N E : DI
Tuple Operations
• Create a tuple by reading n elements from the user.
• Display the tuple.
• Read an index from the user and display the element present at that index.

Set Operations
• Create a set by reading m elements from the user.
• Display the set.
• Read an element to be added to the set and update the set.
• Read an element to be removed from the set and update the set.

nahuohC ayviD forP-B_11P_2003SC_5202


Input and Output Format:
• Read an integer n, representing the number of elements in the tuple.
• Read the next n lines, each containing one integer, and create the tuple.
• Display the created tuple.
• Read an integer representing the index to be accessed and display the element
present at that index.
• Read an integer m, representing the number of elements in the set.
• Read the next m lines, each containing one integer, and create the set.
• Display the original set.
• Read an integer representing the element to be added, update the set, and display
the updated set after addition.
• Read an integer representing the element to be removed, update the set, and
display the updated set after deletion.
Each output should be printed with appropriate messages.

Medicaps University
Note:
• Assume all index values provided are valid.
• The input set may contain duplicate values, but it should store unique elements.
• Refer to the visible test cases for a better understanding and ensure strict
matching with the input/outputs.
Source Code:
[Link]

Page No: 13
n = int(input())

t_list = []

3 9 3 0 1 0 3 S C 5 2 N E : DI
for _ in range(n):
t_list.append(int(input()))

t = tuple(t_list)

print("Tuple:",t)

index = int(input())

print("Accessed Element:", t[index])

nahuohC ayviD forP-B_11P_2003SC_5202


m = int(input())

s = set()

for _ in range(m):
[Link](int(input()))

print("Set:",s)

add_ele = int(input())

[Link](add_ele)

print("After Addition:",s)

rem_ele = int(input())
Medicaps University
[Link](rem_ele)

print("After Deletion:", s)

Execution Results - All test cases have succeeded!

Test Case - 1

User Output
4
1

Page No: 14
2
3
4
Tuple: (1, 2, 3, 4)

3 9 3 0 1 0 3 S C 5 2 N E : DI
0
Accessed Element: 1
4
10
20
30
40
Set: {40, 10, 20, 30}
40

nahuohC ayviD forP-B_11P_2003SC_5202


After Addition: {40, 10, 20, 30}
20
After Deletion: {40, 10, 30}

Test Case - 2

User Output

5
5
10
15
20
25 Medicaps University
Tuple: (5, 10, 15, 20, 25)
3
Accessed Element: 20
6
2
4
6
8
10
10
After Addition: {2, 4, 6, 8, 10, 12}
4

Page No: 15
After Deletion: {2, 6, 8, 10, 12}

3 9 3 0 1 0 3 S C 5 2 N E : DI
nahuohC ayviD forP-B_11P_2003SC_5202
Medicaps University
Date: 2026-02-
[Link]: 8 Exp. Name: Dictionary Operations

Page No: 16
16

Aim:
Write a Python program to perform insertion, update, deletion, and traversal operations

3 9 3 0 1 0 3 S C 5 2 N E : DI
on a dictionary. An initial dictionary containing 10 predefined records is already given in
the program.

Operations to be Performed:
1. Insertion – Insert a new key-value pair into the dictionary using user input.
2. Update – Update the value of an existing key using user input.
3. Deletion – Delete a specified key from the dictionary using user input.
4. Traversal – Traverse the final dictionary and display all key-value pairs.

Input and Output Format:

nahuohC ayviD forP-B_11P_2003SC_5202


1. Read an integer representing the key to be inserted and a string representing its value.
Insert this new key-value pair into the dictionary and display the dictionary after
insertion.
2. Read an integer representing the key to be updated and a string representing the new
value. Update the value of the specified key (only if it exists) and display the dictionary
after the update.
3. Read an integer representing the key to be deleted. Delete the specified key from the
dictionary (only if it exists) and display the dictionary after deletion.
4. Finally, traverse the dictionary and display all key-value pairs.
The program should also display the original dictionary before performing any
operations. Each output should be printed with appropriate messages.

Note:
• All operations must be performed using dictionary methods.
• Perform deletion only if possible; leave the dictionary unchanged.

Medicaps University
• Refer to the visible test cases for better understanding and strictly match with the
input/outputs.
Source Code:
[Link]

Page No: 17
# Initial dictionary with 10 predefined records
student = {
1: "Amit",
2: "Riya",

3 9 3 0 1 0 3 S C 5 2 N E : DI
3: "Kiran",
4: "Neha",
5: "Arjun",
6: "Pooja",
7: "Rahul",
8: "Sneha",
9: "Vikram",
10: "Anjali"
}

print("Original Dictionary:", student)

nahuohC ayviD forP-B_11P_2003SC_5202


a = int(input())
b = input()

student[a] = b

print("After Insertion:", student)

c = int(input())
d = input()

student[c] = d

print("After Update:", student)

e = int(input())
Medicaps University
if e in student:
del student[e]

print("After Deletion:", student)

print("Traversing Dictionary:")

for i in student:
print(i ,":",student[i])
Execution Results - All test cases have succeeded!

Page No: 18
Test Case - 1

User Output

Original Dictionary: {1: 'Amit', 2: 'Riya', 3: 'Kiran', 4:

3 9 3 0 1 0 3 S C 5 2 N E : DI
'Neha', 5: 'Arjun', 6: 'Pooja', 7: 'Rahul', 8: 'Sneha', 9:
'Vikram', 10: 'Anjali'}
11
Suresh
After Insertion: {1: 'Amit', 2: 'Riya', 3: 'Kiran', 4: 'Neha',
5: 'Arjun', 6: 'Pooja', 7: 'Rahul', 8: 'Sneha', 9: 'Vikram',
10: 'Anjali', 11: 'Suresh'}
3
Karthik
After Update: {1: 'Amit', 2: 'Riya', 3: 'Karthik', 4: 'Neha',

nahuohC ayviD forP-B_11P_2003SC_5202


5: 'Arjun', 6: 'Pooja', 7: 'Rahul', 8: 'Sneha', 9: 'Vikram',
10: 'Anjali', 11: 'Suresh'}
5
After Deletion: {1: 'Amit', 2: 'Riya', 3: 'Karthik', 4: 'Neha',
6: 'Pooja', 7: 'Rahul', 8: 'Sneha', 9: 'Vikram', 10: 'Anjali',
11: 'Suresh'}
Traversing Dictionary:
1 : Amit
2 : Riya
3 : Karthik
4 : Neha
6 : Pooja
7 : Rahul
8 : Sneha
9 : Vikram Medicaps University
10 : Anjali
11 : Suresh

Test Case - 2

User Output

Original Dictionary: {1: 'Amit', 2: 'Riya', 3: 'Kiran', 4:


'Neha', 5: 'Arjun', 6: 'Pooja', 7: 'Rahul', 8: 'Sneha', 9:
'Vikram', 10: 'Anjali'}
12
After Insertion: {1: 'Amit', 2: 'Riya', 3: 'Kiran', 4: 'Neha',
5: 'Arjun', 6: 'Pooja', 7: 'Rahul', 8: 'Sneha', 9: 'Vikram',

Page No: 19
10: 'Anjali', 12: 'Meera'}
6
Divya
After Update: {1: 'Amit', 2: 'Riya', 3: 'Kiran', 4: 'Neha', 5:

3 9 3 0 1 0 3 S C 5 2 N E : DI
'Arjun', 6: 'Divya', 7: 'Rahul', 8: 'Sneha', 9: 'Vikram', 10:
'Anjali', 12: 'Meera'}
1
After Deletion: {2: 'Riya', 3: 'Kiran', 4: 'Neha', 5: 'Arjun',
6: 'Divya', 7: 'Rahul', 8: 'Sneha', 9: 'Vikram', 10: 'Anjali',
12: 'Meera'}
Traversing Dictionary:
2 : Riya
3 : Kiran
4 : Neha

nahuohC ayviD forP-B_11P_2003SC_5202


5 : Arjun
6 : Divya
7 : Rahul
8 : Sneha
9 : Vikram
10 : Anjali
12 : Meera

Medicaps University
Date: 2026-02-
[Link]: 9 Exp. Name: Check Even or Odd

Page No: 20
16

Aim:
Write a Python program that reads an integer from the user and checks whether the given

3 9 3 0 1 0 3 S C 5 2 N E : DI
number is even or odd.

Input Format:
• The first line of input is an integer representing the number to be checked.

Output Format:
• Print Even number if the number is even.
• Print Odd number if the number is odd.

Note: The output must exactly match the specified format.


Source Code:

nahuohC ayviD forP-B_11P_2003SC_5202


[Link]

a = int(input())

if a%2==0:
print("Even number")

else:
print("Odd number")

Execution Results - All test cases have succeeded!

Test Case - 1 Medicaps University

User Output

4
Even number

Test Case - 2

User Output

5
Odd number
Exp. Name: Find the Largest of Three Date: 2026-02-
[Link]: 10

Page No: 21
Numbers 16

Aim:
Write a Python program that reads three integers from the user and prints the largest

3 9 3 0 1 0 3 S C 5 2 N E : DI
among them.

Input Format:
• The first line of input is an integer representing the first number.
• The second line of input is an integer representing the second number.
• The third line of input is an integer representing the third number.

Output Format:
• Print the largest of the three numbers in the following format:
Largest number is: <value>

nahuohC ayviD forP-B_11P_2003SC_5202


Note: The output format must exactly match the given format.
Source Code:

[Link]

a = int(input())
b = int(input())
c = int(input())

if a>b:
if a>c:
print("Largest number is:", a)
else:
print("Largest number is:", c)

else: Medicaps University


if b>c:
print("Largest number is:", b)
else:
print("Largest number is:", c)

Execution Results - All test cases have succeeded!

Test Case - 1

User Output
10
20

Page No: 22
30
Largest number is: 30

3 9 3 0 1 0 3 S C 5 2 N E : DI
Test Case - 2

User Output

45
12
33
Largest number is: 45

Test Case - 3

nahuohC ayviD forP-B_11P_2003SC_5202


User Output

5
5
5
Largest number is: 5

Medicaps University
Exp. Name: Factorial of a Number using Date: 2026-02-
[Link]: 11

Page No: 23
While Loop 16

Aim:
Write a Python program that reads an integer from the user and calculates its factorial

3 9 3 0 1 0 3 S C 5 2 N E : DI
using a while loop.

Input Format:
• The first line of input is an integer representing the number.

Output Format:
• Print the factorial of the given number in the following format:
Factorial: <value>
Source Code:

[Link]

nahuohC ayviD forP-B_11P_2003SC_5202


a = int(input())
b= 1
while a>1:
b *= a
a-=1

print("Factorial:", b)

Execution Results - All test cases have succeeded!

Test Case - 1

User Output Medicaps University

5
Factorial: 120

Test Case - 2

User Output

7
Factorial: 5040
Exp. Name: Fibonacci Sequence Using For Date: 2026-02-
[Link]: 12

Page No: 24
Loop 16

Aim:
Write a Python program that reads an integer n from the user and prints the first n terms

3 9 3 0 1 0 3 S C 5 2 N E : DI
of the Fibonacci sequence using a for loop.

Input Format:
• The first line of input is an integer representing the number of terms n.

Output Format:
• Print the Fibonacci sequence up to n terms in a single line, with each term
separated by a space.
Source Code:

[Link]

nahuohC ayviD forP-B_11P_2003SC_5202


a = int(input())

b = [0,1,1]

i=0

while i<a:
if i>2:
[Link](b[i-1] + b[i-2])

i += 1

print(*b, "\n")
Medicaps University

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

5
0 1 1 2 3
Page No: 25 3 9 3 0 1 0 3 S C 5 2 N E : DI nahuohC ayviD forP-B_11P_2003SC_5202 Medicaps University
Test Case - 2

0 1 1 2 3 5 8 13
User Output

8
Date: 2026-02-
[Link]: 13 Exp. Name: Sum of Prime Numbers

Page No: 26
18

Aim:
Write a Python program that reads two integers representing a start range and an end

3 9 3 0 1 0 3 S C 5 2 N E : DI
range, and computes the sum of all prime numbers within this range (both inclusive).

Input Format:
• The first line contains an integer representing the starting value of the range.
• The second line contains an integer representing the ending value of the range.

Output Format:
• Print the sum of all prime numbers present in the given range in the format:
Sum of prime numbers: <sum>

Constraints:

nahuohC ayviD forP-B_11P_2003SC_5202


• The starting and ending values are positive integers.
• The start value is less than or equal to the end value.
Source Code:

[Link]

a = int(input())
b = int(input())

sum = 0

for num in range(a,b+1):


if num>1:
prime = True
for i in range(2, int(num**0.5)+1):
if num%i == 0: Medicaps University
prime = False
break

if prime:
sum += num

print("Sum of prime numbers:", sum)

Execution Results - All test cases have succeeded!


Test Case - 1

Page No: 27
User Output

5
15
Sum of prime numbers: 36

3 9 3 0 1 0 3 S C 5 2 N E : DI
Test Case - 2

User Output

8
10
Sum of prime numbers: 0

nahuohC ayviD forP-B_11P_2003SC_5202


Medicaps University
Exp. Name: Simple Calculator Using Date: 2026-02-
[Link]: 14

Page No: 28
Classes 28

Aim:
Write a Python program that defines a class Calculator with two methods:

3 9 3 0 1 0 3 S C 5 2 N E : DI
• add(a, b) - returns the sum of a and b.
• subtract(a, b) - returns the difference of a and b.

Create an object of the Calculator class named calc and use it to perform the required
operations. Read two numbers from the user, and print:
• The result of the addition
• The result of the subtraction

Input Format:
• The first line contains an integer representing the first number a.
• The second line contains an integer representing the second number b.

nahuohC ayviD forP-B_11P_2003SC_5202


Output Format:
• The first line contains the sum of a and b.
• The second line contains the difference between a and b.
Source Code:

[Link]

# Write code here for the class


class Calcu:
def add(self,a,b):
return a+b

def subtract(self,a,b):
return a-b
Medicaps University

# Create object of Calculator class


calc = Calcu()

# User input
num1 = int(input())
num2 = int(input())

# Perform calculations
print("Addition:", [Link](num1, num2))
print("Subtraction:", [Link](num1, num2))
Execution Results - All test cases have succeeded!

Page No: 29
Test Case - 1

User Output

3 9 3 0 1 0 3 S C 5 2 N E : DI
3
Addition: 6
Subtraction: 0

Test Case - 2

User Output

5
15

nahuohC ayviD forP-B_11P_2003SC_5202


Addition: 20
Subtraction: -10

Test Case - 3

User Output

25
10
Addition: 35
Subtraction: 15

Medicaps University
Exp. Name: Inheritance using a Class Date: 2026-02-
[Link]: 15

Page No: 30
Hierarchy 28

Aim:
Write a Python program to create a class hierarchy consisting of a base class and two

3 9 3 0 1 0 3 S C 5 2 N E : DI
derived classes to demonstrate the concept of inheritance.

Program Requirements:
1. Create a base class named Person with:
• An attribute name.
• A method show_name() that displays the name of the person.
Name: <name>
2. Create two derived classes:
• Student, inheriting from Person, with a method study() that prints:
<name> is studying
• Teacher, inheriting from Person, with a method teach() that prints:

nahuohC ayviD forP-B_11P_2003SC_5202


<name> is teaching
3. Read the student name and teacher name from the user.
4. Create objects of both derived classes using the input values.
5. Demonstrate inheritance by:
• Calling the base class method using both objects.
• Calling the respective derived class methods.

Input Format:
• The first line contains a string representing the student name.
• The second line contains a string representing the teacher name.

Output Format:
The output should be printed in the following order:
• Display the student name using the base class method.
• Display the teacher name using the base class method.

Medicaps University
• Display the student study message.
• Display the teacher's teaching message.
Source Code:
[Link]

Page No: 31
# Base class
class Person:
name = ""
def show_name(self):

3 9 3 0 1 0 3 S C 5 2 N E : DI
print("Name:", [Link])

# Derived class Student


class Student(Person):
def study(self):
print([Link] +" is studying")

# Derived class Teacher


class Teacher(Person):

nahuohC ayviD forP-B_11P_2003SC_5202


def teach(self):
print([Link] +" is teaching")

# # -------- Input Section --------


# student_name = input()
# teacher_name = input()

# # -------- Object Creation --------


# student = Student(student_name)
# teacher = Teacher(teacher_name)

# # Access base class method


# student.show_name()
# teacher.show_name()
Medicaps University
# # Access derived class methods
# [Link]()
# [Link]()

stu = input()
tea = input()

student = Student()
teacher = Teacher()

[Link] = stu
[Link] = tea

Page No: 32
student.show_name()
teacher.show_name()

[Link]()

3 9 3 0 1 0 3 S C 5 2 N E : DI
[Link]()

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Rahul

nahuohC ayviD forP-B_11P_2003SC_5202


Anitha
Name: Rahul
Name: Anitha
Rahul is studying
Anitha is teaching

Test Case - 2

User Output

Michael
Philips
Name: Michael
Name: Philips
Michael is studying Medicaps University
Philips is teaching
Exp. Name: Method Overriding using Date: 2026-02-
[Link]: 16

Page No: 33
Inheritance 28

Aim:
Write a Python program to implement method overriding in a class hierarchy.

3 9 3 0 1 0 3 S C 5 2 N E : DI
Program Requirements:
• Create a base class named Vehicle with a method description() that prints:
This is a vehicle
• Create a derived class named Car that inherits from Vehicle and overrides the
description() method to print:
This is a car
• Create objects of both the base class and the derived class.
• Call the description() method using both objects to demonstrate method
overriding.

nahuohC ayviD forP-B_11P_2003SC_5202


Input Format:
• No user input is required.

Output Format:
The output should consist of two lines:
• The first line displays the output of the base class method.
• The second line displays the output of the overridden method in the derived class.
Source Code:

[Link]

# Base class
class Vehicle:
def description(self):
print("This is a vehicle")
Medicaps University
# Derived class
class Car:
def description(self):
print("This is a car")

# Create objects
v = Vehicle()
c = Car()

# Call methods
[Link]() # Calls base class method
[Link]() # Calls overridden method in derived class
Execution Results - All test cases have succeeded!

Page No: 34
Test Case - 1

User Output

This is a vehicle

3 9 3 0 1 0 3 S C 5 2 N E : DI
This is a car

nahuohC ayviD forP-B_11P_2003SC_5202


Medicaps University
Date: 2026-02-
[Link]: 17 Exp. Name: Demonstrate Encapsulation

Page No: 35
28

Aim:
Write a Python program to demonstrate encapsulation by creating a class with a private

3 9 3 0 1 0 3 S C 5 2 N E : DI
attribute and accessing it using a public method.

Program Requirements:
• Create a class named Student.
• Inside the constructor, define a private data member named __marks and initialize
it with the value 90.
• Define a public method get_marks() that returns the value of the private data
member.
• Create an object of the class and display the marks using the public method.

Output Format:

nahuohC ayviD forP-B_11P_2003SC_5202


• Print the marks in the format:
Marks: 90

Note: The code for the output is already provided. Write the code for the class referring to
the requirements specified.
Source Code:

[Link]

# write your code here...


class Student:
def get_marks(self):
return 90

Medicaps University
s = Student()
print("Marks:", s.get_marks())

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Marks: 90
Date: 2026-02-
[Link]: 18 Exp. Name: Abstract Base Class

Page No: 36
28

Aim:
Write a Python program to create an abstract base class representing a geometric shape

3 9 3 0 1 0 3 S C 5 2 N E : DI
and implement it using a derived class.

Program Requirements:
• Create an abstract class named Shape using the ABC module.
• Define an abstract method named area() inside the base class.
• Create a derived class named Circle that inherits from the Shape class.
• Implement the area() method in the derived class to calculate the area of a circle
using the formula:

Area = π × r × r

• Read the radius of the circle as input.

nahuohC ayviD forP-B_11P_2003SC_5202


• Create an object of the Circle class and display the calculated area.

Input Format:
• The first line contains a floating-point number representing the radius of the circle.

Output Format:
• Print the area of the circle in the format:
Area of circle: <value>
Where the 'value' is formatted to two decimal places.

Note:
• Use the abc module to define the abstract base class.
• Use the constant pi from the math module for calculation.
• The result should be displayed as a floating-point value.

Note: Partial code is provided; please complete the missing code according to the Medicaps University
requirements mentioned.
Source Code:
[Link]

Page No: 37
from abc import ABC, abstractmethod
import math

# Abstract base class

3 9 3 0 1 0 3 S C 5 2 N E : DI
class Shape(ABC):

@abstractmethod

def area(self):
pass

# Derived class Circle


class Circle(Shape):

nahuohC ayviD forP-B_11P_2003SC_5202


def __init__(self, radius):
[Link] = radius

def area(self):
return [Link] * [Link] * [Link]

# -------- Input --------


r = float(input())
c = Circle(r)
print("Area of circle: {:.2f}".format([Link]()))

Medicaps University
Execution Results - All test cases have succeeded!

Test Case - 1

User Output

5
Area of circle: 78.54

Test Case - 2

User Output
12
Area of circle: 452.39

Page No: 38
Test Case - 3

User Output

3 9 3 0 1 0 3 S C 5 2 N E : DI
24.5
Area of circle: 1885.74

nahuohC ayviD forP-B_11P_2003SC_5202


Medicaps University
Exp. Name: File Handling with Exception Date: 2026-04-
[Link]: 19

Page No: 39
Handling 01

Aim:
Write a Python program to implement a function that reads data from a file and handles

3 9 3 0 1 0 3 S C 5 2 N E : DI
file-related exceptions such as FileNotFoundError and PermissionError.

Program Requirements
1. Define a function named read_file(filename) that:
• Attempts to open the given file in read mode.
• Displays the contents of the file if it exists and is accessible.
• Handles the following exceptions:
• If the file does not exist, display:
Error: File not found
• If permission to read the file is denied, display:
Error: Permission denied

nahuohC ayviD forP-B_11P_2003SC_5202


Input Format:
• The first line contains a string representing the file name.

Output Format:
• If the file exists and can be read:
<contents of the file>
• If the file does not exist:
Error: File not found
• If permission is denied:
Error: Permission denied
Source Code:

Medicaps University
[Link]

Page No: 40
# Type Content here...
def read_file(filename):
try:
with open(filename,'r') as file:

3 9 3 0 1 0 3 S C 5 2 N E : DI
content = [Link]()
print(content)
except FileNotFoundError:
print("Error: File not found")
except PermissionError:
print("Error: Permission denied")

filename = input()
read_file(filename)

nahuohC ayviD forP-B_11P_2003SC_5202


[Link]

Beautiful is better than ugly.


Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Everything matters.

Execution Results - All test cases have succeeded!


Medicaps University
Test Case - 1

User Output

[Link]
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Everything matters.

Page No: 41
Test Case - 2

User Output

[Link]

3 9 3 0 1 0 3 S C 5 2 N E : DI
Error: File not found

nahuohC ayviD forP-B_11P_2003SC_5202


Medicaps University
Date: 2026-04-
[Link]: 20 Exp. Name: Zero Division Error

Page No: 42
01

Aim:
Write a Python program that reads two integers from the user and performs division. The

3 9 3 0 1 0 3 S C 5 2 N E : DI
program should handle the ZeroDivisionError exception gracefully if the
denominator is zero.

Program Requirements:
1. Read two integers:
• The numerator.
• The denominator.
2. Perform the division operation.
3. If the denominator is zero, catch the ZeroDivisionError and display the message:
Cannot divide by zero
4. If the division is valid, display the result of the division.

nahuohC ayviD forP-B_11P_2003SC_5202


Input Format:
• The first line contains an integer representing the numerator.
• The second line contains an integer representing the denominator.

Output Format:
• If division is possible, print the result of the division formatted to two decimal
places.
• If the denominator is zero, print:
Cannot divide by zero
Source Code:

[Link]

try:
n = int(input()) Medicaps University
d = int(input())

r = n/d
print(f"{r:.2f}")

except ZeroDivisionError:
print("Cannot divide by zero")

Execution Results - All test cases have succeeded!


Test Case - 1

Page No: 43
User Output

5
0
Cannot divide by zero

3 9 3 0 1 0 3 S C 5 2 N E : DI
Test Case - 2

User Output

5
5
1.00

nahuohC ayviD forP-B_11P_2003SC_5202


Test Case - 3

User Output

0
5
0.00

Medicaps University
Exp. Name: File Handling with Multiple Date: 2026-04-
[Link]: 21

Page No: 44
Exception Handling 01

Aim:
Write a Python program to read the contents of a file and handle the exceptions

3 9 3 0 1 0 3 S C 5 2 N E : DI
FileNotFoundError and PermissionError gracefully.

Program Requirements:
• Read the file name from the user.
• Attempt to open the file in read mode.
• If the file exists and is accessible, display its contents.
• If the file is not found, display:
Error: File not found
• If the user does not have permission to access the file, display:
Error: Permission denied

nahuohC ayviD forP-B_11P_2003SC_5202


Input Format:
• The first line contains a string representing the file name.

Output Format:
• If the file is read successfully:
<contents of the file>
• If the file is not found:
Error: File not found
• If permission is denied:
Error: Permission denied
Source Code:

Medicaps University
[Link]

Page No: 45
try:
f = input()

with open(f,'r') as fi:

3 9 3 0 1 0 3 S C 5 2 N E : DI
co = [Link]()
print(co)

except FileNotFoundError:
print("Error: File not found")

except PermissionError:
print("Error: Permisssion denied")

nahuohC ayviD forP-B_11P_2003SC_5202


[Link]

CodeTantra
Start coding in 60 mins

Execution Results - All test cases have succeeded!

Test Case - 1

User Output Medicaps University

[Link]
CodeTantra
Start coding in 60 mins

Test Case - 2

User Output

[Link]
Error: File not found
Exp. Name: File Operations using Date: 2026-04-
[Link]: 22

Page No: 46
Exception Handling 01

Aim:
Write a Python program that opens a file and reads its contents. The program should

3 9 3 0 1 0 3 S C 5 2 N E : DI
demonstrate the use of the finally block to ensure that the file is closed properly,
regardless of whether an exception occurs or not.

Program Requirements:
• Read the file name from the user.
• Attempt to open the file in read mode and display its contents.
• Handle the following exception:
• If the file does not exist, display:
Error: File not found
• Use a finally block to ensure that:
• If the file is opened successfully, it is closed properly, and displays:

nahuohC ayviD forP-B_11P_2003SC_5202


File closed successfully
• If the file could not be opened, display:
No file to close

Input Format:
• The first line contains a string representing the file name.

Output Format:
• If the file exists and can be opened:
<contents of the file>
File closed successfully
• If the file does not exist:
Error: File not found
No file to close
Source Code:

Medicaps University
[Link]

Page No: 47
file = None

try:
f = input()

3 9 3 0 1 0 3 S C 5 2 N E : DI
file = open(f,'r')
print([Link]())

except FileNotFoundError :
print("Error: File not found")

finally:
if file:
[Link]()
print("File closed successfully")

nahuohC ayviD forP-B_11P_2003SC_5202


else:
print("No file to close")

[Link]

Hello World

[Link]

Python Programming

[Link] Medicaps University

AI is the future!

[Link]

123 Programming!

Execution Results - All test cases have succeeded!


Test Case - 1

Page No: 48
User Output

[Link]
Hello World
File closed successfully

3 9 3 0 1 0 3 S C 5 2 N E : DI
Test Case - 2

User Output

[Link]
Error: File not found
No file to close

nahuohC ayviD forP-B_11P_2003SC_5202


Medicaps University
Exp. Name: Validate a Variable name and Date: 2026-04-
[Link]: 23

Page No: 49
an Email Address 01

Aim:
Write a Python program that uses regular expressions to validate:

3 9 3 0 1 0 3 S C 5 2 N E : DI
1. A variable name, and
2. An email address

Program Requirements
1. Read a string representing a variable name from the user and validate it using regular
expressions based on the following rules:
• The variable name must start with a letter (a–z or A–Z) or underscore (_).
• It may contain letters, digits, and underscores only.
• It must not start with a digit.
2. Read a string representing an email address and validate it based on the following
rules:

nahuohC ayviD forP-B_11P_2003SC_5202


• The email must contain exactly one '@' symbol.
• The username part may contain: letters (a–z, A–Z), digits (0–9), dots (.),
underscores (_), percent (%), plus (+), hyphen (-)
• The domain name may contain: letters, digits, dots (.), hyphens (-)
• The email must end with a valid domain extension of at least two letters (e.g.,
.com, .org, .in, .edu).
3. Display:
Valid variable name
• If the variable name is valid, otherwise display:
Invalid variable name
4. Display:
Valid email address
• If the email address is valid, otherwise display:
Invalid email address

Medicaps University
Input Format:
• The first line contains a string representing the variable name.
• The second line contains a string representing the email address.

Output Format:
• Print the validation result for the variable name.
• Print the validation result for the email address.
Source Code:
[Link]

Page No: 50
import re

v = input()
e = input()

3 9 3 0 1 0 3 S C 5 2 N E : DI
var = r'^[A-Za-z_][A-Za-z0-9_]*$'

if [Link](var,v):
print("Valid variable name")
else:
print("Invalid variable name")

dm = r'^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$'

if [Link](dm, e):

nahuohC ayviD forP-B_11P_2003SC_5202


print("Valid email address")
else:
print("Invalid email address")

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

my_var1
user@[Link]
Valid variable name

Medicaps University
Valid email address

Test Case - 2

User Output

1var
test@[Link]
Invalid variable name
Valid email address
User Output

Page No: 51
count_value
user#[Link]
Valid variable name
Invalid email address

3 9 3 0 1 0 3 S C 5 2 N E : DI
Test Case - 4

User Output

9num
user@com
Invalid variable name
Invalid email address

nahuohC ayviD forP-B_11P_2003SC_5202


Medicaps University
Date: 2026-04-
[Link]: 24 Exp. Name: Math Module Operations

Page No: 52
01

Aim:
Write a Python program that uses the built-in math module to perform the following

3 9 3 0 1 0 3 S C 5 2 N E : DI
mathematical operations using user-provided input values:
• Calculate the square root of a given number.
• Calculate the factorial of a given number.
• Calculate the power of a number raised to another number.

Program Requirements
1. Read an integer representing the number whose square root is to be calculated.
2. Read an integer representing the number whose factorial is to be calculated.
3. Read two integers representing the base and exponent for the power calculation.
4. Display the results using the math module functions.

nahuohC ayviD forP-B_11P_2003SC_5202


Input Format:
• The first line contains an integer n1 - the number for the square root calculation.
• The second line contains an integer n2 - the number for factorial calculation.
• The third line contains an integer base.
• The fourth line contains an integer exp - the exponent.

Output Format:
Display the results in the following format:
Square root: <value>
Factorial: <value>
Power: <value>

Constraints:
• n1 ≥ 0

• n2 ≥ 0

Medicaps University
Source Code:
[Link]

Page No: 53
import math

# Read inputs
n1 = int(input())

3 9 3 0 1 0 3 S C 5 2 N E : DI
n2 = int(input())
base = int(input())
exp = int(input())

# Perform calculations using math module


s = [Link](n1)
f = [Link](n2)
p = [Link](base,exp)

# Display results
print("Square root:", s)

nahuohC ayviD forP-B_11P_2003SC_5202


print("Factorial:",f)
print("Power:",p)

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

16
5
2
3
Square root: 4.0 Medicaps University
Factorial: 120
Power: 8.0

Test Case - 2

User Output

0
0
5
3
Page No: 54 3 9 3 0 1 0 3 S C 5 2 N E : DI nahuohC ayviD forP-B_11P_2003SC_5202 Medicaps University
Factorial: 1
Power: 125.0
Exp. Name: Date and Time Handling using Date: 2026-04-
[Link]: 25

Page No: 55
datetime Module 01

Aim:
Write a Python program that reads a date and time from the user and processes it using

3 9 3 0 1 0 3 S C 5 2 N E : DI
Python’s built-in datetime module.
The input will be provided as a single string representing date and time in the format:
YYYY-MM-DD HH:MM:SS
The program must convert this string into a datetime object and display the individual
components of the given date and time, namely the year, month, day, hour, minute, and
second.

Input Format:
• A single line containing a date and time string in the specified format.

Output Format:

nahuohC ayviD forP-B_11P_2003SC_5202


• Display the extracted components in the following format:
Year: <year>
Month: <month>
Day: <day>
Hour: <hour>
Minute: <minute>
Second: <second>

Constraints:
• The date provided will be a valid calendar date.
Source Code:

Medicaps University
[Link]

Page No: 56
from datetime import datetime

date_string = input()

3 9 3 0 1 0 3 S C 5 2 N E : DI
# Convert the input string into a datetime object using the given
format
dt = [Link](date_string, "%Y-%m-%d %H:%M:%S")

# Display year
print("Year:",[Link])

# Display month
print("Month:",[Link])

# Display day

nahuohC ayviD forP-B_11P_2003SC_5202


print("Day:",[Link])

# Display hour
print("Hour:",[Link])

# Display minute
print("Minute:",[Link])

# Display second
print("Second:",[Link])

Execution Results - All test cases have succeeded!

Medicaps University
Test Case - 1

User Output

2024-08-15 10:30:45
Year: 2024
Month: 8
Day: 15
Hour: 10
Minute: 30
Second: 45
User Output

Page No: 57
2021-06-07 03:04:05
Year: 2021
Month: 6
Day: 7
Hour: 3

3 9 3 0 1 0 3 S C 5 2 N E : DI
Minute: 4
Second: 5

nahuohC ayviD forP-B_11P_2003SC_5202


Medicaps University
Exp. Name: Basic Array Operations using Date: 2026-04-
[Link]: 26

Page No: 58
Numpy 01

Aim:
Write a Python program to create two NumPy arrays using user input and perform the

3 9 3 0 1 0 3 S C 5 2 N E : DI
following element-wise operations:
• Addition
• Subtraction
• Multiplication
• Division

Input Format:
• The first line contains an integer n, representing the size of the arrays.
• The second line contains n space-separated integers representing the first array.
• The third line contains n space-separated integers representing the second array.

nahuohC ayviD forP-B_11P_2003SC_5202


Output Format:
Print four lines:
• Result of addition
• Result of subtraction
• Result of multiplication
• Result of division

Note: Each result should be displayed as a NumPy array.

Constraints:
• 1 ≤ n ≤ 100
• All elements are integers.
• Division by zero will not be provided in input.
Source Code:

Medicaps University
[Link]

Page No: 59
import numpy as np

# Read size of arrays


n = int(input())

3 9 3 0 1 0 3 S C 5 2 N E : DI
# Read elements of first array
arr1 = [Link](list(map(int, input().split())))
arr2 = [Link](list(map(int, input().split())))

# Read elements of second array

# Perform and display:


# Addition
# Subtraction

nahuohC ayviD forP-B_11P_2003SC_5202


# Multiplication
# Division

print(arr1+arr2)
print(arr1-arr2)
print(arr1*arr2)
print(arr1/arr2)

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

3 Medicaps University
10 20 30
123
[11 22 33]
[ 9 18 27]
[10 40 90]
[10. 10. 10.]

Test Case - 2

User Output
Page No: 60 3 9 3 0 1 0 3 S C 5 2 N E : DI nahuohC ayviD forP-B_11P_2003SC_5202 Medicaps University
[ 16 160]
1.6]
[10 26]
[6 6]
8 16
2 10

[4.
Exp. Name: Data Filtering and Selection Date: 2026-04-
[Link]: 27

Page No: 61
using Numpy 01

Aim:
Write a Python program to create a NumPy array and perform data filtering and selection

3 9 3 0 1 0 3 S C 5 2 N E : DI
based on the following conditions:
• Select all elements greater than 20.
• Select all elements between 15 and 35 (inclusive).
• Select all even numbers from the array.

Program Requirements
• Read an integer n representing the number of elements in the array.
• Read n space-separated integers to create a NumPy array.
• Display the original array.
• Filter and display:
1. Elements greater than 20

nahuohC ayviD forP-B_11P_2003SC_5202


2. Elements between 15 and 35 (inclusive)
3. Even numbers in the array

Input Format:
• The first line contains an integer n, representing the size of the array.
• The second line contains n space-separated integers representing the elements of
the array.

Output Format:
• First, print the original array.
• Then print the following, each in a line:
1. Elements greater than 20
2. Elements between 15 and 35
3. Even numbers

Medicaps University
Constraints:
• 1 ≤ n ≤ 100
• Array elements are integers.

Note:
• Refer to the visible test cases and strictly match with the input and outputs.
Source Code:
[Link]

Page No: 62
import numpy as np

# Read number of elements


n = int(input())

3 9 3 0 1 0 3 S C 5 2 N E : DI
# Read array elements

arr = [Link](list(map(int, input().split())))


# Convert input to NumPy array

# Print original array


print("Original Array:")
print(arr)

nahuohC ayviD forP-B_11P_2003SC_5202


# Filter and print:
# 1. Elements greater than 20
print("Elements greater than 20:")
print(arr[arr>20])

# 2. Elements between 15 and 35


print("Elements between 15 and 35:")
print(arr[(arr>=15) & (arr<=35)])

# 3. Even numbers
print("Even numbers:")
print(arr[arr%2==0])

Medicaps University
Execution Results - All test cases have succeeded!

Test Case - 1

User Output

7
10 15 20 25 30 35 40
Original Array:
[10 15 20 25 30 35 40]
Elements greater than 20:
[25 30 35 40]
Elements between 15 and 35:
Even numbers:
[10 20 30 40]

Page No: 63
Test Case - 2

User Output

3 9 3 0 1 0 3 S C 5 2 N E : DI
5
13579
Original Array:
[1 3 5 7 9]
Elements greater than 20:
[]
Elements between 15 and 35:
[]
Even numbers:

nahuohC ayviD forP-B_11P_2003SC_5202


[]

Medicaps University
Exp. Name: Statistical Analysis using Date: 2026-04-
[Link]: 28

Page No: 64
Pandas 01

Aim:
Write a Python program that uses the Pandas library to read data from a CSV file and

3 9 3 0 1 0 3 S C 5 2 N E : DI
compute the following statistical measures:
1. Mean
2. Median
3. Standard Deviation

Input Format:
• The first line contains a string representing the CSV file name.

Output Format:
• Display the computed statistics in the following format:
Mean:

nahuohC ayviD forP-B_11P_2003SC_5202


<values>
Median:
<values>
Standard Deviation:
<values>
Each statistical result should be displayed for all numeric columns in the dataset.
Source Code:

Medicaps University
[Link]

Page No: 65
import pandas as pd

# Input: CSV file name


filename = input()

3 9 3 0 1 0 3 S C 5 2 N E : DI
# Read CSV file
df = pd.read_csv(filename)

# Compute statistics
print("Mean:")
print([Link](numeric_only=True))

print("Median:")
print([Link](numeric_only=True))

nahuohC ayviD forP-B_11P_2003SC_5202


print("Standard Deviation:")
print([Link](numeric_only=True))

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

[Link]

Medicaps University
Mean:
A 17.5
B 27.5
C 37.5
dtype: float64
Median:
A 17.5
B 27.5
C 37.5
dtype: float64
Standard Deviation:
A 6.454972
B 6.454972
Page No: 66 3 9 3 0 1 0 3 S C 5 2 N E : DI nahuohC ayviD forP-B_11P_2003SC_5202 Medicaps University
dtype: float64
Exp. Name: DataFrame Manipulation Date: 2026-04-
[Link]: 29

Page No: 67
Operations 01

Aim:
Write a Python program to load a dataset from a CSV file into a Pandas DataFrame and

3 9 3 0 1 0 3 S C 5 2 N E : DI
perform the following DataFrame manipulation operations:
• Display the original DataFrame.
• Sort the DataFrame based on the first column.
• Filter and display rows where the values in the first column are greater than the
mean of that column.
• Display the second column of the DataFrame, if it exists.
• Display the first five rows of the DataFrame.

Input Format:
• The first line contains a string representing the CSV file name.

nahuohC ayviD forP-B_11P_2003SC_5202


Output Format:
The output should display:
• Original DataFrame
• Sorted DataFrame
• Filtered DataFrame (values greater than mean)
• Selected column (if available)
• First 5 rows of the DataFrame

Note:Refer to the visible test cases and strictly match with the input and outputs.
Source Code:

Medicaps University
[Link]

Page No: 68
import pandas as pd

# Input: CSV file name


filename = input()

3 9 3 0 1 0 3 S C 5 2 N E : DI
# Load dataset
df = pd.read_csv(filename)

# Display original DataFrame


print("Original DataFrame:")
print(df)

fo = [Link][0]
# Sort DataFrame by first column
print("Sorted DataFrame:")

nahuohC ayviD forP-B_11P_2003SC_5202


print(df.sort_values(by=fo))

mo = df[fo].mean()
# Filter rows where values in first column are greater than its
mean
print("Filtered DataFrame:")
print(df[df[fo] > mo])

# Select second column if it exists

print("Selected Column:")
if len([Link]) >1:
print(df[[Link][1]])
else:
print("No second column")
# Display first 5 rows
print("First 5 rows of DataFrame:") Medicaps University
print([Link]())
[Link]

Page No: 69
A,B,C
10,20,30
15,25,35
20,30,40

3 9 3 0 1 0 3 S C 5 2 N E : DI
25,35,45
30,40,50
35,45,55

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

nahuohC ayviD forP-B_11P_2003SC_5202


[Link]
Original DataFrame:
A B C
0 10 20 30
1 15 25 35
2 20 30 40
3 25 35 45
4 30 40 50
5 35 45 55
Sorted DataFrame:
A B C
0 10 20 30
1 15 25 35

Medicaps University
2 20 30 40
3 25 35 45
4 30 40 50
5 35 45 55
Filtered DataFrame:
A B C
3 25 35 45
4 30 40 50
5 35 45 55
Selected Column:
0 20
1 25
4 40
5 45

Page No: 70
Name: B, dtype: int64
First 5 rows of DataFrame:
A B C
0 10 20 30

3 9 3 0 1 0 3 S C 5 2 N E : DI
1 15 25 35
2 20 30 40
3 25 35 45
4 30 40 50

nahuohC ayviD forP-B_11P_2003SC_5202


Medicaps University

You might also like