Exp. Name: Determine whether the last digit of a
S.No: 1 : Date: 2024-03-22
number is Even or Odd
Aim:
Jyothi and Sakshi are playing a game in which Jyothi gives a task to Sakshi to print whether the last digit of the
number is even or odd. For this Sakshi needs your help.
Can you help Sakshi?
Input Format:
The input line reads an integer representing the number.
Output Format:
‘The output line prints whether the last digit is Even or Odd.
Source Code:
LastDigit. py
a = int(input("Enter a number: *))
Af ak
print("Odd")
else:
print(“Even")
Execution Results - all test cases have succeeded!
Test Case - 1
User Output
Enter a number
1234
Even
Test Case - 2
User Output
Enter a numbers
5019
oad
Page No: 1
ID: 23¢8C25,
BNM Institute Of Technology 2023-27-CSE-CExp. Name: Compare two numbers using nested
S.No: 2
: conditionals
Date: 2024-03-22
im:
Amit is someone who frequently finds himself comparing various things. He recently encountered a situation
where he needed to compare two numerical values repeatedly. To simplify this process, he decided to write a
Python program.
He aims to develop a program that swiftly determines whether the first number is greater, lesser, or equal to the
second. With this program, Amit hopes to streamline his comparison tasks and save valuable time.
Could you assist Amit in crafting this Python program?
Input format:
The first two lines are the integers,
Output format:
Prints a string indicating whether the first number is greater, lesser, or equal to the second number.
Source Cod
compareNumbers py
a = int(input())
b = int(input())
if arb:
print (“First number 1s greater")
elif a
print("Both nunbers are equal”)
else
print("First number is lesser")
Execution Results - all test cases have succeeded!
Test Case - 1
User Output
8
5
First nunber is greater
Test Case - 2
User Output
19
85,
First nunber is lessen
Test Case - 3
User Output
Page No: 2
ID: 23¢SC25,
BNM Institute Of Technology 2023-27-CSE-CBoth nunbers are equal
10
10
€:0N abeg | $29SIE2 “a D-ASI-22-E20e) ABojouyray Jo anynsu| WES.No: 3 Exp. Name: Eldest of three Date: 2024-03-22
im:
Ina classroom, there are three students of varying ages. The teacher, who is responsible for the class, has @
specific task at hand to determine the oldest student among the three. To achieve this, the teacher plans to
develop a Python program that takes the ages of the students as input and identifies the eldest among them,
Could you help the teacher in crafting this Python program?
Input format:
The first three lines are the integers that represent the ages of the three students.
Output format:
The output is the integer that represents the age of the elder student.
Source Cod
eldestAge.py
int (input ())
int (input ())
int (input ())
if arb:
if act
print (a)
else:
print(c)
else
if beer
print(b)
else:
print(c)
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
12
14
3B
1
Test Case -2
User Output
u
43
23
43
Page No: 4
ID: 23¢8C25,
BNM Institute Of Technology 2023-27-CSE-CS:ON aGeg /$29S3E2 “Gi
Test Case - 3
User Output
14.
19)
I-ASI-22-E20e)ABojouyray Jo anysu| WNES.No: 4 Exp. Name: Factorial Calculator Date: 2024-03-22
Sophia is working on a program to calculate the factorial of a given number. For that, she wants to implement a
function called calculate factorial that takes a positive integer as input and returns its factorial
Input format:
The input is an integer.
Output format:
The output is the integer that represents the factorial of the user-given integer.
Source Cod
factorial. py
def calculate_factorial (nunber)
Af number <= 1
return number
else:
return ((number) * calculate_factorial (number-1))
user_number = int(input())
factorial_result = calculate factorial (user_number)
print (factorial_result)
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
10
3628800
Test Case -2
User Output
6
722
ID: 23€SC25_ Page No: 6
BNM Institute Of Technology 2023-27-CSE-CS.No: 5 Exp. Name: Fibonacci series. Date: 2024-03-22
im:
‘Ata local community center, a math club is hosting a workshop to introduce students to the concept of Fibonacci
numbers, The workshop aims to inspire students’ interest in mathematics by demonstrating the beauty and
simplicity of this famous sequence.
AAs part of the workshop, the organizers plan to demonstrate how to generate the Fibonacci series
programmatically using Python. Imagine you have participated in the workshop and you are tasked to write a
Python program for that, Can you able to write it?
Input format:
The input is the integer n.
output format:
The output is the n terms of the Fibonacci series.
Source Cod
fibonacci.py
n= Ant(input())
def Fib(n):
ifn
return n
ese:
return (Fib(n-2) + #2b(n-2))
for i in range(n):
print(fib(i), end =‘ *)
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
4
@1i2
Test Case - 2
User Output
10
@1123581321 34
Page No: 7
ID: 23¢8C25,
BNM Institute Of Technology 2023-27-CSE-CS.No: 6 Exp. Name: Binary Coded Decimal Date: 2024-03-23
im:
Rani, who loves electronics, is exploring digital electronics and learning about different ways of representing
numbers in binary code. Her teacher gave her a task to convert a number into Binary Coded Decimal (BCD)
format. Can you help Rani with this task?
BCD representation:
BCD represents each decimal digit with a 4-bit binary code.
Let us find the BCD representation of 15,
1 in binary format - 0001
5 in binary format - 0101
So the BCD representation is 00010101
Input format:
The input is the integer.
Output format:
The output is the BCD representation of the given integer.
Source Code:
bei
y
no = input()
def converter(number) :
bin = ()
if nunber == @
return ‘9200
hile number
rem = number % 2
number //= 2
bin. append(rem)
bin. append(1)
rev = bin!
4]
bste
-Join(map(str, rev))
while len(bstr)!= 4:
bstr
"+ bstr
return bstr
l= t]
for i in str(no):
new = converter(int())
Lappend(new)
s = '*.Jein(1)
print(s)
ID: 23€SC25__ Page No: 8
BNM Institute Of Technology 2023-27-CSE-CExecution Results - all test cases have succeeded!
Test Case - 1
User Output
15
eaeie1e1
Test Case -2
User Output
253
eeie0ie10011
Page No: 9
ID: 23¢8C25,
BNM Institute Of Technology 2023-27-CSE-CS.No: 7 Exp. Name: Store the marks in the dictionary Date: 2024-03-22
im:
Imagine you are a teacher at a high school, and you need to record the names and marks of N students for a
recent exam, To streamline the process and ensure accuracy, you decide to develop a Python program.
Your program will prompt you to input the names and marks of each student individually. Once you have entered
this information forall N students, the program will store itn a dictionary, associating each student's name with
their exam marks
Could you develop such a Python program to assist you in managing student records effectively?
Input format:
The input is the integer that represents the number of students.
Enter the name and marks for each student.
Output format:
The output is the dictionary of students and their marks.
Source Code:
studentData.py
print ({input(F*Name of student {i+}
rpange(int (input()))})
Float (input(F"Marks of student {441}: ")) for 4 in
Execution Results - all test cases have succeeded!
Test Case - 1
User Output
3
Nane_of student 1
John
Marks of student 1:
785
Nane oF student 2:
Daniel
Marks of student 2:
79.5
Nane_of student
Siraj
Marks of student 3:
89.2
‘(lohn": 78-5, “Daniel: 79.5, "Siraj": 89.2}
Test Case -2
User Output
5
Nane of student 1
ID: 23CSC25__ Page No: 10
BNM Institute Of Technology 2023-27-CSE-CSwathi
Marks of student 1:
90.1
Nane_oF student 2
Sangeetha
Marks of student 2:
902
Nane_of student 3:
Samatha
Marks of student 3:
90.23
Nane_of student 4
‘Aanya
Narks of student
925
Nane_of student 5:
Anvith
Narks of student
935
('Swathi": 9.1, “Sangeetha': 90.2, ‘Samatha’: 90.23, “Aanya': 92.5, “Anvith': 93,5)
ID: 23CSC25_ Page No: 11
stitute Of Technology 2023-27-CSE-C
BNMS.No: 8 Exp. Name: Project management tool Date: 2024-04-08
im:
Imagine you're building a tool to help teams manage their projects. One feature you want to add is the ability for
Users to organize their tasks based on specific words they choose,
Here's a simple example:
You have a list of tasks like ‘no bun’, ‘bug bun bug bun bug bug’ ‘bunny bug’, and ‘buggy bug bug buggy’. Now,
if the user picks the word ‘bug’, you want the tasks with ‘bug’ mentioned the most to come first. So, you need to
rearrange the list so that tasks with ‘bug’ mentioned a lot are at the top.
Can you create a Python program to do this and improve our project management tool?
Input format:
The first line is the list of strings separated by comma ()
The second line is the user-specified word.
Output format:
The output is the list of strings after re-arrangement.
Source Cod
wordsarrangement .py
inp = input()
List = inp.split(’,
key = input()
word_count = [(word.count(key), word) for word in List]
sorted = [word for count, word in sorted(word_count, reverse = True)]
print(sorted)
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
no bun,bug bun bug bun bug bug,bunny
bug.buggy bug bug bug
bug
[ibugey bug bug bugay’
“bug bun bug bun bug bug’, “bunny bug’, "no bun]
Test Case - 2
ID: 23CSC25_ Page No: 12
BNM Institute Of Technology 2023-27-CSE-CUser Output
‘one one two,two three two two two,one one
‘one two, three four
‘one
[’one one one tuo", “one one two", “two three two two two's
"three four")
ID: 23CSC25__ Page No: 13
BNM Institute Of Technology 2023-27-CSE-CS.No: 9 Exp. Name: Frequency of the number Date: 2024-03-22
im:
You are part of a research team analyzing data from an experiment. The team needs a tool to quickly assess the
frequency of different experimental outcomes. Your goal is to create a Python program that takes a list of numeric
values as input, counts the frequency of each unique value, and produces a dictionary. This dictionary should have
the unique values as keys and their respective frequencies as values
Input format:
The input isthe list of integers separated by commat.),
Output format:
Print the dictionary with distinct integers as keys and the count of those integers as their corresponding values.
Source Cod
dictionary3.py
a = input()
a.split(",")
= mapCint, 1)
d= {}
for i in ls
Af 1 not An d.keys():
dfi] = @
d[i] +2
print(d)
In Results - All test cases have succeeded!
Test Case - 1
User Output
4,2,3,1,2,3,2,2,2,3,33,1,1
(i 4 2: 5, 3: 5)
Test Case - 2
User Output
4,1,1,222,22,22,22,33,33,3,3,33,33,3
(4: 3, 222: 1, 22: 3, 33: 4, 3: 3
Test Case - 3
User Output
33,44,55,66,77,88,11,22,22.33
(22: 2, aa: 1, 5: 4, 66: 1, 77: 1, Ger 1, Wd a, 2: 2)
ID: 23CSC25_ Page No: 14
BNM Institute Of Technology 2023-27-CSE-CS.No: 10 Exp. Name: College Fest Fun Game Registration Date: 2024-03-22
im:
Excitement fils the air as the college fest approaches. As part of the festivities, the organizing committee has
planned a fun game that promises to be a highlight of the event. To participate in the game, students were
required to register in advance, and each registered participant received a unique token consisting of a number.
As amember of the organizing committee, you've been tasked with automating the check-in process for the fun
‘game. You need to write a Python program that will allow you to verify whether a participant is registered for the
‘game by checking their token number against the list of registered token numbers. ifthe participant's token
number is found in the list, they will be allowed to patticipate; otherwise, they will be denied entry.
Input format:
The first line is the list of token numbers.
The second line is the token number.
Output format:
The output is the index value of the token number if the token number is found otherwise print "Not found”.
Note:
Assume there are no duplicates in the list.
Source Code
festregister.py
(anput())
int (input ())
def index(1, n)
for i, item in enumerate(1
Af item == str(n)
return i
Af str(n) in 1:
1 = Lsplit( *)
paint (index(1, ))
print("Not found")
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
1234567
5
4
Test Case - 2
User Output
ID: 23CSC25__ Page No: 15
BNM Institute Of Technology 2023-27-CSE-C23131412791
18
Not Found
9L-ON aGeg $2983" “a1
3-4S9-22-EZOZ ABojouypa, Jo armnsuy WNS.No: 11 Exp. Name: Celestial Celebration Planner Date: 2024-03-22
im:
You are organizing a celestial-themed celebration event, and you've envisioned a mesmerizing pyramid of stars to
add a touch of celestial brilliance to the ambiance. To achieve this, you've decided to create a program that prints
2 pyramid-like star pattern using recursion. Write a program that encourages the participants to interact with the
program and witness the recursive magic that shapes the starty pyramid.
The pyramid of 5 rows will look
Constraints:
0 <= no of rows < 20
Input Format:
Single line of input contains an integer representing the no of rows
‘Output Format:
Print the required pattern using recursion if the rows is a positive integer, otherwise, print "Inv
rows’
Note: For simplicity, the driver code has already been provided.
def print_pynamid(num_rows, current_row):
Af current_row > num_rows
return
else:
print(* '*(num_rows-current_row), end = '')
print (‘*"*(2*current_row-1))
return print_pyramid(num_rows, current_row+1)
if _nane, main”
nun_levels = int(input())
Af num_levels <= @ or num_levels > 20:
print("Invalid rows")
else:
# generate and display the pyramid pattern
print_pyramid(num_levels, 1)
Execution Results - all test cases have succeeded!
Test Case - 1
User Output
ID: 23€SC25__ Page No: 17
BNM Institute Of Technology 2023-27-CSE-CTest Case - 2
User Output
2
Test Case - 3
User Output
5
Invalid rows:
ID: 23CSC25__ Page No: 18
BNM Institute Of Technology 2023-27-CSE-CS.No: 14 Exp. Name: Binary to decimal Date: 2024-03-25
im:
Sam has a peculiar calculator that displays results exclusively in binary format. Despite his lack of familiarity with
binary numbers, Sam was tasked by his teacher to compute the sum of two integers. After using the calculator, he
obtained the result in binary format. Can you assist Sam in converting the binary result to its equivalent decimal
format?
Input Format:
The input consists of a binary number representing the result of the sum performed by Sam's calculator.
Output Format:
The output should be the decimal equivalent of the binary result obtained from the calculator.
Note:
Ifthe input is not a valid binary number, display the result as “Invalid!
Source Code:
bintodecimal.py
a = input()
def convert(num):
ans = @
char = List(num)
char = [Ant(4) for 4 in char]
jee
for 1 in range(1, len(char)+1):
ans += (244) * (char[-i])
jeea
print(ans)
co
for tina
and 4
af:
peint(“Invalid”)
else
convert(a)
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
1011
Fry
ID: 23CSC25__ Page No: 19
BNM Institute Of Technology 2023-27-CSE-CTest Case - 2
User Output
1000001
a
Test Case - 3
User Output
10256
Invalid
ID: 23CSC25__ Page No: 20
BNM Institute Of Technology 2023-27-CSE-CS.No: 15 Exp. Name: Length of the string Date: 2024-03-25
im:
Karan has a word with him and is eager to determine the length of the word. However, he prefers to exclude any
spaces within the word. Can you assist Karan in finding the length of the word while excluding spaces?
Constraints:
1 <= length of the string <= 100
Input format:
The input isa string,
Output format:
The first line is the original length of the string
The second line is the length after avoiding spaces in the string,
Sample Test Case:
Code tantra
14
10
Explanation:
The actual length of the string = 14
Number of spaces present = 4
Therefore Avoiding spaces in string length gives us the value = 10
Instructions:
+ Your input and output must follow the input and output layout mentioned in the visible sample test case.
+ Hidden test cases will only pass when users’ input and output match the expected input and output,
+ The code for taking input and calling the function has been provided to you in the editor, you just need to
complete the function body.
Source Code:
length. py
def length(str1):
print(Len(ste1))
stra. split’
+ Join( Last)
print(1en(new))
asinput()
Length(a)
Execution Results - all test cases have succeeded!
Test Case - 1
User Output
Code tantra
ID: 23CSC25_ Page No: 21
BNM Institute Of Technology 2023-27-CSE-C22 0N aGeg *$2383Ee “AT
1
Fr
Test Case - 2
User Output
Arguments
23,
2
‘D-ASI“L2-€20e! ABojouyral Jo arms
WaS.No: 16 Exp. Name: Abbreviated names Date: 2024-03-25
im:
The graduation ceremony at your university is just around the corner, and the organizing committee is busy
preparing for the event. As part of the ceremony, each graduate's name will be announced as they walk across
the stage to receive their diploma. To streamline the process and ensure accuracy, the committee has decided to
abbreviate the first and middle names of the graduates, while keeping their last names intact.
‘As a member of the graduation ceremony organizing committee, you've been assigned the task of developing a
program to generate the abbreviated names of the graduates. The program should take each graduate's full
name as input and output the abbreviation, with only the first letter of the first and middle names displayed,
followed by the full ast name.
For example, ifthe input name is “John William Smith’, the output should be "W.Smith"
Input format:
The input isthe full name.
Output format:
The output is the abbreviated name.
Note:
If there is only a last name given, the abbreviated name is the same as of input as there are no first and middle
names.
Source Code:
abbreviatedName. py
a = input()
List = a.split(' ')
Af Jen(List:
print(a)
else
new_list = []
for i in List:
new_Listappend(4[@])
new_list.pop(-1)
nen_List-append(List[-1])
new word = *.".Join(new list)
print (new word)
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
John William Smith
2.W.Smath
Test Case - 2
ID: 23CSC25__ Page No: 23
BNM Institute Of Technology 2023-27-CSE-CUser Output
George
George
v2:0N aGeg $2983" “a1
I-ESI-22-E20Z)_ ABojouy>ay Jo armanst
WaExp. Name: Arha’s Birthday Mystery Date: 2024-03-25
Atha, an avid calendar artist, has a unique tradition of marking her birthday date in every yearly calendar.
However, there's one elusive calendar where the celebration went unmarked! Your mission is to generate the
missing calendar for the special year that holds the unmarked date.
Your Quest:
+ Arha will provide you with the mysterious year she has lost.
+ Utilize your coding skills to craft the calendar for that specific year.
+ Print a 3-column calendar for an entire year
Source Cod
calenderofyear.py
‘import calendar
import calendar
ID: 23CSC25_ Page No: 25
column width: 2
#lines per week: 1
number of spaces betueen month columns: 1
fino. of months per column: 3
year = Ant(input())
cal = calendar. TextCalendar(calendar. SUNDAY)
print(cal.formatyear(year, 2, 1, 1, 3))
stitute Of Technology 2023-27-CSE-C
Execution Results - All test cases have succeeded!
=
a
Test Case - 1
User Output
2001
2001
January February, March
Su Mo Tu We Th Fr Sa_Su Mo Tu We Th Fr Sa_Su Mo Tu We Th Fr Sa
123456 123 123
789i 45678910 4567 8 910
14 15 16 17 18 19 20 11 12 13 14 15 16 17 11 12 13 14 15 16 17
21 22 23 24 25 26 27 18 19 26 21 22 23 24 18 19 20 21 22 23 24
28 29 30 31 25 26 27 28 25 26 27 28 29 30 31
‘april May dune
Tu We Th Fr Sa_Su Mo Tu We Th Fr Sa_Su Mo Tu We Th Fr Sa
Suanicmen7 uonaaraae 1
wiwnm 678 9@ik 345678
15 16 17 18 19 26 21_13 14 15 1617 18 19 10 11 12 13 14 15 16
22 23 24 25 26 27 28 20 21 22 23 24 2526 17 18 19 20 21 22 23
su29
30
27,
28
29 30 31
24
35
26 27 28
Fa)
30
auly
‘August
Septenber,
su
Tu we Th
Fe
sa
su
Tu we Th
Fr
sa
su
No
Tu we Th
Fe
sa
Suaar
ee
ol e
10 11 12
2B
vy
7289
18
a
3
a5 6
15,
16
17 18 19,
20
2
a2
Fy
14 15 16
a7,
18
16
11213
14
a5
22
24 25 26
27,
28
Ft
20
21 22 23,
2a
25
16
7
18 19 20
2
22,
23
30
31
26
27
28 29 30
3
23
24
25 26 27
28
29)
30
October
Novenber
Decenber
su
Tu we Th
Fr
sa
su
Tu we Th
Fr
sa
su
Tu we Th
Fe
sa
eae
1
9 te 1
2
B
é7 8
18
a5 6
1a
15
16 17 18
19
20
a
12
13 14 15,
16
7,
16
it 12 13
14
15
2
22
23 24 25,
26
27,
18
19
20 21 22
23
28
16
7
18 19 20
2
22
28
29
30 31
25
26
27 28 29,
3
23
24
25 26 27
28
29)
30
31
Test Case - 2
User Output
2005)
2005,
January
February
March
su
Tu We Th
Fe
Sa
su
Tu we Th
Fr
sa
Su
Tu We Th
Fe
sa
123
123
a5 6
39 10
a
a2
39 10
a
a2
9 10)
a1 12 13,
14
15,
3
14
15 16 17,
18
Fy
Fe
14
15 16 17
18
19
16
7
a8 19 20
21
22
20
2a
22 23 24
25
26
FA
2
22 23 24
25
26
2
24
25 26 27
28
29
27,
27
28
729 30 31
30
3
‘Apri
May
Bune
su
Tu we Th
sa
su
Tu we Th
Fr
sa
su
No
Tu we Th
Fe
sa
aaa
aaa
5 67
10 11 12,
3
18
@
7289
Fr
Fr
18
Ft
21314
a5
16
BRloln |e
17 18 19
28
2
2
3
14 15 16
a7,
18
7
18
19 20 21
22
23
22
23
24 25 26
27
28
Fr
20
21 22 23
24
28
25
26 27 28
29
30
29
31
26
27
28 29 30
duly
‘August
September
su
Tu We Th
Sa
Tu We Th
Fr
sa
No
Tu we Th
Sa
23 4
1
Saeed
oH |e
PECTS
12
13
5
Gaed
9 16
Fr
i
a2 13 14
15
16
5
16 17 18
19
20
12
13 14 15
16
7,
7
18
19 20 21
2
3
22
23 24 25
26
2
18
19
20 21 22
23
28
28
25
26 27 28
29
30
29
30 22
25
26
27 28 29
30
31
october
Novenber
Decenber
su
Tu We Th
Fr
sa
su
Tu we Th
Fr
sa
su
Tu we Th
Fe
sa
123
1
45 6
2 910
ry
2
67 8
18
9 1
1213
15
3
14
45 16 17,
18
19
My
2
13 1415
16
v7
16
7
18 19 20
2
22
28
2
22 23 28
25
26
18
19
20 21 22
23
24
ID: 23CSC25__ Page No: 26
BNM Institute Of Technology 2023-27-CSE-C25 26 27 28 29 30 31
23 24 25 26 27 28 29 27 28 29 30
30 31
L2:0N aed “$2383E “AT
I-ASI-22-E20e) ABojouypay Jo amsu| WNES.No: 18 Exp. Name: Line in a file Date: 2024-03-25
im:
Ashraf, a computer science student, is passionate about books and technology. He envisions creating an online
library management system that will revolutionize how users access and manage their book collections. As part of
his project, Ashrif has prepared several files containing lists of book titles, each representing a different category
or genre.
{As part of his project development, Ashrif has created a Python program that prompts users to enter the name of
a file containing a list of book titles and an alphabetical character. The program then searches the file for a line
starting with the specified character and prints out the book title if found. If no book title starting with the
specified character is found, the program prints “Not found’
Can you replicate his program in Python?
Input format:
The first line is the file name.
The second line is the alphabetical character.
Output format:
The output is the line in the file starting with the user-given character otherwise displays "Not found".
Source Code
lineinfile.py
file
key
nput()
input ()
with open(file, ‘r') as f:
Lines = f.readlines()
#Lines = [1[@:-1] for 1 in lines]
new = [1 for i in lines if i[0]
key]
Af not new:
print("Not found")
else:
prant(new[@})
filei.txt
The Power of Habit
Sapiens: A Brief History of Humankind
Becoming
Educated
The Inmontal Life of Henrietta Lacks
file2.txt
Harry Potter and the Sorcerer's Stone
The Great Gatsby
To Kill a Mockingbird
Pride and Prejudice
The Catcher in the Rye
ID: 23CSC25__ Page No: 28
BNM Institute Of Technology 2023-27-CSE-CExecution Results - all test cases have succeeded!
Test Case - 1
User Output
filet .txt
s
Sapiens: A Brief History of Hunankind
Test Case - 2
User Output
filet. txt
F
Not Found
ID: 23CSC25__ Page No: 29
BNM Institute Of Technology 2023-27-CSE-CS.No: 19 Exp. Name: Display the contents of the file Date: 2024-03-25
im:
Ina bustling city neighborhood, a group of avid readers has formed a book club to share their love for literature.
Each member of the book club contributes to a shared digital library by uploading files containing lists of book
recommendations, reviews, and discussion topics.
AAs part of their book club activities, the members decided to create a Python program that can read the contents
of any file in their digital library. The program will be used to quickly access and review the contents of various
files uploaded by the members.
If the specified file does not exist, the program should gracefully handle the error by printing the message “File
does not exist” This feature ensures that users are notified if they attempt to access a file that has not been
uploaded to the digital library
Input format:
The input is the file name,
Output format:
The output is the contents of the file if the file exists otherwise print "File does not exist".
Source Code:
leexistence.py
File = input()
try:
with open(file, 'r') as f:
lines = f.readlines()
new = (]
for line in Lines!
if Line[-1] == *\n':
n= Line[@:-1]
new. append(n)
else:
new. append( line)
for § in new:
print (4)
except Exception:
print("File does not exist")
file1
xt
To Kill a Mockingbird by Harper Lee
1984 by George Orwell
The Great Gatsby by F. Scott Fitzgerald
Pride and Prejudice by Jane Austen
The Catcher in the Rye by J.D. Salinger
File2.txt
ID: 23CSC25__ Page No: 30
BNM Institute Of Technology 2023-27-CSE-CThe themes of love and friendship in literature
The impact of technology on storytelling
Exploring dystopian worlds in fiction
Analyzing unreliable narrators in novels
The role of humor in literature
Execution Results - all test cases have succeeded!
Test Case - 1
User Output
filet txt
To Kill a Mockingbird by Harper Lee
1984 by George Orwell
The Great Gatsby by F. Scott Fitzgerald
Pride and Prejudice by Jane Austen
The Catcher in the Rye by J.D. Salinger
Test Case - 2
User Output
files.axt
File does not exist
ID: 23CSC25_ Page No: 31
stitute Of Technology 2023-27-CSE-C
BNMExp. Name: File Eligibility for Submission Date: 2024-03-25
Rathika is preparing to submit her project abstract to the university. The university has imposed a rule stating that
the abstract file must not exceed 250 characters, including spaces. Rathika has finalized her abstract but is
uncertain whether it meets the university’ criteria,
Your task is to create a Python program that helps Rathika determine whether her abstract file is eligible for
submission. The program should read the content of the abstract from a text file, count the total number of
characters (including spaces), and then provide feedback to Rathika about the eligibility of her abstract.
Ensure that your program handles situations where the file does not exist or if there are any issues with file
reading
Note:
+ Refer to the displayed test cases for the input and output format.
Source Code
abstract. py
file = input()
try:
with open(file, ‘r') as f:
contents = #.read()
List = list(contents)
length = len(List)
Sf Length <= 250:
print(“eligibie")
print(F*Total characters: {length}")
else:
print("not eligible")
print(f"Total characters:
‘Length)")
except Exception:
print("file does not exist")
filel.txt
This paper explores a relatively less popular source of clean energy.
An application is proposed for the same, in which a speaker and 9 transformer
are used to convert noise produced by car horn into electrical energy
File2.txt
Inverters are widely used in the domestic as well as industrial environments to serve
as second line of source in case of power cut form the electricity utility grids.
Inverter is the device that powers the electric appliances in the event of the power
failure. Inverter as the name implies first converts AC to OC for
charging the battery and then inverts DC to AC for powering the electric gadgets.
ID: 23CSC25__ Page No: 32
BNM Institute Of Technology 2023-27-CSE-Cfile3.txt
Inverters are widely used in the domestic as well as industrial environments to serve as
second line of source in case of power cut form the electricity utility grids.
file4.txt
When a fire breaks out, time is of the essence. Prompt measures need to be taken to evacuate
the trapped people and contain the fire before it spreads out of hand. However, to
accomplish this we need a system that can detect fires before it is too late.
This fully automated Fire Detection and Alarm System is equipped with a temperature sensor
and @ 555 timer IC. This fire detection can sense changes in temperature and sound an alarm
in case of fires.
Execution Results - all test cases have succeeded!
Test Case - 1
User Output
filet txt,
eligible
Total characters:220
Test Case -2
User Output
file2.txt,
not eligible
Total chanacters:403,
Test Case - 3
User Output
file.txt
File does not exist
ID: 23CSC25_ Page No: 33
stitute Of Technology 2023-27-CSE-C
BNMExp. Name: Check whether the point lies inside or
S.No: 21
°: on the boundary of a circle
Date: 2024-03-25
Aim:
AAs part of a robotics project, you're working on programming a drone to navigate through a series of waypoints
ina confined area represented by circular regions. To ensure the drone stays within the designated zones, you
need to develop a Python program that verifies if each waypoint lies inside or on the boundary of a given circular
region.
1. Define a Point class with attributes x and y to represent the coordinates of a point.
2. Define a Circle class with attributes center and radius, where the center is a Point object representing the
Circle's center and radius is a number representing the circle's radius
3. Write a function named point in circle that takes a Circle object and a Point object as arguments and
returns True ifthe point lies inside or on the circle’s boundary.
Note: The code for handling inputs and outputs has already been provided to you.
Source Cod
pointlie:
py
class Circle:
def _init_(self, Centre, radius)
self.centre = (Centre.x, Centre.y)
self.radius = radius
class Point
def _init_(self, x, y)
self.x = x
self.y = y
def point_in_circle(eircle, point)
4 = ((((point.x - circle.centre[@])**2)+((point.y - circle.centre(1})*#2))**(1/2))
Af d <= cirele.radius:
return True
return False
center_x
center_y
float (input("x-coordinate of the circle center:
Float (input("y-coordinate of the circle center
# Input: Circle radius
radius = float(input("Radius of the circle: "))
4 Input: Point coordinates
point_x = float(input("
point_y = float(input("
coordinate of the point
coordinate of the point:
cirele =
incle(Point(center_x, center_y), radius)
point = Point(point_x, point_y)
print("Is the point inside or on the boundary of the circle?", point_in_circle(circle,
point))
In Results - All test cases have succeeded!
ID: 23CSC25_ Page No: 34
BNM Institute Of Technology 2023-27-CSE-CTest Case - 1
User Output
wecoondinate of the circle center:
a a
y-coordinate of the circle center 5
= 2
&
Radius of the circle: 2
5 2
x-coordinate of the point S
g
3 g
g
y-coordinate of the point 4
4
Is the point inside or on the boundary of the circle? True
Test Case -2
User Output
xcoordinate of the circle center:
gy
0 a
coordinate of the circle center: g
a 5
7 *
Radius of the circle: g
&
5
xccoondinate of the point 3
6 2
y-coordinate of the point s
a 6
1s the point inside or on the boundary of the circle? False 2
BNMS.No: 22 Exp. Name: Calculate the arc length Date: 2024-03-25
You're a software engineer working for a company specializing in creating tools for architects and engineers. One
of the features requested by your clients is the ability to calculate the arc length of an angle within a circle, To
meet this need, you decide to develop a Python program that calculates the arc length of an angle within a circle.
Here's how you plan to implement the solution:
1. Define a class named AreLength with the following attributes:
+ radius: representing the radius of the circle.
+ angle: representing the angle (in degrees)
2.Inside the AreLength class, define a method named calculate_arc length that calculates the arc length using
the formula:
+ arclength=radiusxangle(inradians)
+ Ensure to convert the angle from degrees to radians.
Note: The code for handling inputs and outputs has already been provided to you.
Source Code:
arclength.py
class AreLength:
def _init_(self, radius, angle):
self.radius = radius
self.angle = angle
self.angle = (3.101*self.angle)/18@
def calculate_arc_length(self):
return self.radius * self.angle
radius
‘oat (input(*radius: "))
angle = float(input("angle (in degrees): "))
arc = Arclength(radius, angle)
arc_length = arc.calculate_are_length()
print(*arc length:", round(arc_length, 2))
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
radius:
5
angle (in degrees):
45
are length: 3.93
ID: 23CSC25__ Page No: 36
BNM Institute Of Technology 2023-27-CSE-CTest Case - 2
User Output
radius:
10
‘angle (in degrees):
90
are length: 15.71
ID: 23€SC25_ Page No: 37
BNM Institute Of Technology 2023-27-CSE-CExp. Name: Non-Vowel Counter Date: 2024-03-25
Ai
To get an internship in CodeTantra you have been given a task to create a Python class NenVewelCounter according
to the given specifications:
4, Initialize an instance variable to an empty string in the constructor.
5. Implement a method setstring that takes user input and assigns it to the instance variable.
6. Implement another method countNonvowels to count the number of non-vowels (excluding a, e, i, 0, u)
present in the string stored in the instance variable, Return the total count of non-vowels found in the
string
Input Format:
The input isa string containing alphabetic characters, both uppercase and lowercase, and special characters.
Output Format
The output is an integer representing the total count of non-vowels present in the input string including special
characters,
Note:
+ Consider space also as a special character.
+The input string may contain alphabetic characters in both uppercase and lowercase and special
characters,
Your task is to implement the NenVouelcounter class based on the given specifications.
Source Code
NonVowelCounter.py
class NonVowelCounter:
def _init_(self):
self.string
def setString(self, string)
self.string = string
def countNonVowels (self):
c-e@
List = list(self.string)
for i in List:
Af {not dn “teed Tou
cara
return ¢
input_string = input()
counter = NonVowelCounter()
counter. setString(input_string)
result = counter.countNonVowels()
print (result)
Execution Results - All test cases have succeeded!
ID: 23CSC25__ Page No: 38
stitute Of Technology 2023-27-CSE-C
BNMTest Case - 1
User Output
Hello World!
9
Test Case - 2
User Output
‘AEIOU also considered as vowels right?
23
ID: 23CSC25__ Page No: 39
BNM Institute Of Technology 2023-27-CSE-CExp. Name: Count the magical words Date: 2024-03-25
In a mystical village in India, There is a cave which contains treasure. To unlock the doors of that cave one needs
to create a class MagicalWordsCount which contains a method count_magical_words that counts the magical
‘words in a given string. A magical word is a word that contains an uppercase character, a lowercase character,
and a numerical character.
‘Are you ready to unlock the doors of the cave to get the treasure?
Input Format:
The input isa string,
ID: 23CSC25__ Page No: 40
‘Output Format:
‘The output is an integer representing the number of magical words in the given string,
Source Code:
MagicalWordsCount.py
class MagicalWordscount:
det (self)
pass
def count_magical_words(self, L):
c=e
for i in L
char = list(4)
#1, #2, #3 = 0, 0, 0
for jin char:
Af j-Asupper()
flea
if j.islower()
f2=4
if jismumeric():
fea
stitute Of Technology 2023-27-CSE-C
BNM
Af fl and #2 and #3:
ced
return ¢
magical_words_counter = MagicalWordsCount()
word_list = input().split(”
magical_count = magical_words_counter.count_magical_words(word_list)
print (magical_count)
Execution Results - all test cases have succeeded!
Test Case - 1
User Output
Alpha4Numeric words in this sentence are 1Lyon aBeg G2383€2 “al
Test Case -2
User Output
Hello World 123
I-ASI-22-E20e) ABojouy>ay Jo aMysu| WNES.No: 25 Exp. Name: Compound Interest Calculation Date: 2024-03-25
im:
Your father withdraws a loan of amount 'P’ from SBI for a period of T' years at an interest rate, ‘R’. As a Computer,
Science student, write a Python program using the OOPS concept (class) that calculates the total interest
(compound interest charged by the bank) and the total amount that is to be paid by your father:
+ Create a class CI
+ Define a constructor to set attributes for the principal amount (P), interest rate (R), and time period (1)
+ Implement a method named interest to calculate and return the total interest using the compound
interest formula,
+ Implement a method named total to calculate and return the total amount to be paid
Formula:
Total Amount = P (1+ (R/ 100))"
Total interest = Total Amount - P
Input Format:
Single line of input contains three space separated float values representing the principal amount, rate of interest,
and the time period respectively
Output Format:
First line contains the total interest to be paid
Second line contains the total amount to be paid
Note: The code for handling inputs and printing results is already provided in the editor. Your task is to
implement the required classes based on the given specifications.
Source Cod
InterestCalculat
ID: 23€SC25_ Page No: 42
BNM Institute Of Technology 2023-27-CSE-Cclass CL:
def _init_(self, p, r, t)
self.p = p
self.r =r
self.t=t
self.total = @
def interest(self)
self.total = self.pt((1+(self.r/108) )**self.t)
return self.total - self.p
def totals(self):
return self.total
a = input().split(’ *)
a= [float(t) for 4 in a]
port=a
“tp, ry t = map(float, input().split())
Total_interest = CI(p, r, t)
print(“Total Interest:", round(Total_Interest.interest(), 2))
print(“Total Anount:", round(Total_Interest.total(), 2))
fa = input().split(’ *)
a = [float(i) for i in a]
tp rte
T= CL(p, r, t)
print(#"Total Interest: {round(TI.interest(), 2)}")
print(#"Total Anount: {round(TI.totals(), 2)}")
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
100055
Total Interest: 276.28
Total Anount: 1276.28
ID: 23€SC25_ Page No: 43
BNM Institute Of Technology 2023-27-CSE-CTest Case - 2
User Output
50000 6 1.5
Total Interest: 4566.84
Total Anount: 5456.84
Test Case - 3
User Output
40000 61
Total Interest: 2400.0
Total Anount: 42400.0
ID: 23CSC25_ Page No: 44
stitute Of Technology 2023-27-CSE-C
BNMS.No: 26 Exp. Name: Library Management - Encapsulation Date: 2024-03-25
You're building a Python program to manage information about books in a library. Create a class Book with the
following features:
+ The class should have two private attributes, title and author.
+ Write a constructor that takes a title and an author, and sets the private attributes.
+ Implement methods get title and get author to retrieve the values of the title and author.
+ Add a method set title that takes a new title as a parameter and updates the title attribute.
+ Add a method set_author that takes a new author as a parameter and updates the author attribute.
Create an instance of the Book class, set its title and author using the provided methods, and display the title and
author using the get title and get author methods.
Input format:
The first line is a string representing the initial title of the book.
The second line isa string representing the initial author of the book.
The third line is a string representing the new title to be set.
The fourth line is a string representing the new author to be set.
Output format:
Display the initial title and author using the get.title and get author methods.
Display the title and author after setting the new values.
Note: The code for handling inputs, creating objects, invoking methods, and printing results is already provided
in the editor. Your task is to implement the required classes based on the given specifications.
Source Cod
ID: 23CSC25__ Page No: 45
BNM Institute Of Technology 2023-27-CSE-Cclass Book
def _init_(self, title, author):
self. title = title
self.author = author
def get_title(self):
return self.title
def get_author(self)
return self.author
def set_title(self, title):
self.title = title
def set_author(self, author):
self.author = author
# Inputs
initial_title = input().strip()
initial_author = input().strip()
new title = input().strip()
new_author = input().strip()
# Create an instance of Book
book = Book(initial_title, initial_author)
# Display initial title and author
print(#*Initial Title: {book.get_title()}')
print(#*Initial Author: {book.get_author()}")
# Set new title and author
book. set_title(new title)
book. set_author(new_suthor)
# Display new title and author
print(#'New Title: {book.get_titie()}")
print(#'New Author: {book.get_author()}*)
Execution Results - all test cases have succeeded!
Test Case - 1
User Output
Harry Potter
J.K. Rowling
‘The Hobbit
J.RR Tolkien
ID: 23CSC25__ Page No: 46
BNM Institute Of Technology 2023-27-CSE-CInitial Title: Harry Potter
Initial Author: J. K. Rowling
New Title: The Hobbit
New Author: 3. R. R. Tolkien
Test Case - 2
User Output
‘The Da Vinci Code
Dan Brown
‘The Catcher in the Rye
J.D Salinger
Initial Title: The Da Vinel Code
Initial Author: Dan Brown
New Title: The Catcher in the Rye
New Author: J.D Salinger
ID: 23¢SC25_ Page No: 47
stitute Of Technology 2023-27-CSE-C
BNMS.No: 27 Exp. Name: Fee Calculator Date: 2024-03-25
im:
To get an internship in CodeTantra you have been given a task to create a Python class Feecaleulater according
to the given specifications:
7. [Implement a method setoetaiis that takes the student's name, roll number, basic fee, and attendance
percentage.
8. Implement another method TetaiFee to calculate the fee based on attendance percentage. If the
attendance percentage is <=50 total fees will be the basic fee + 20 percent of the basic fee, If the
attendance percentage is <=75 and >50 total fees will be the basic fee + 15 percent of the basic fee, and if
the attendance percentage is >75%, they should not pay any extra fee other than the basic fee. Return the
total fee.
Input Format:
The first line reads a string representing the student's name.
The second line reads an integer representing the roll number of the student.
The third line reads an integer representing the basic fee.
The fourth line reads a float value representing the attendance percentage of the student
‘Output Format:
The output is afloat value representing the total fee of the student.
Your task is to implement the Feecateulator class based on the given specifications,
Source Cod
Feecalculator.py
ID: 23CSC25__ Page No: 48
BNM Institute Of Technology 2023-27-CSE-Cclass FeeCalculater:
def _init_(self)
self.name
self.rollno = @
self.fee = @
self.percentage = @
def SetDetails(self, name, rollno, fee, percentage)
self.name = nane
self.rollno = rolino
self.fee = fee
self.percentage = percentage
def TotalFee(self)
if self.percentage <= 50:
return 1.2*self. fee
elif self.percentage <=75 and self.percentage >50:
return 1.15*self.fee
else:
return self. fee
name=input()
roLIno=int (input())
Feexint(input())
percentage=float input ())
student = FeeCalculator()
student1. SetDetails(nane, rol ino, fee, percentage)
print(student1. TotalFee())
Execution Results - all test cases have succeeded!
Test Case - 1
User Output
Raghu
20798
15000
74S.
17250.8
Test Case - 2
User Output
Rakesh
181965
20000
78.
20000
ID: 23CSC25_ Page No: 49
BNM Institute Of Technology 2023-27-CSE-C05 :0N aGeg *$2983€ “a1
Test Case - 3
User Output
Jhansi
191844
17000
48.95
20400.0
I-4SI-22-E20e) ABojouyray Jo aMsu| WE