0 ratings0% found this document useful (0 votes) 992 views39 pagesCodeTantra Python Short
solutions in python small
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Exp. Name: Determine whether the last digit of a
SNe number is Even or Odd
Date: 2024-03-22
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
| print(*Odd” if int(input("Enter a number: "))%2 else “Even")
In Results - All test cases have succeeded!
Test Case - 1
User Output
Enter a number:
1234
Even
Test Case - 2
User Output
Enter @ number
5019
odd
23CSC25_ Page No: 1
1D:
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, b = int(input()), int(input())
print(*First number is greater" if a>b else "Both numbers are equal” if at
umber is lesser")
b else “First
Execution Results - all test cases have succeeded!
Test Case - 1
User Output
8
5
First number is greater
Test Case - 2
User Output
19
85
First number is lesser
Test Case - 3
User Output
10
10
Both nunbers are equal
23CSC25_ Page No:2
1D:
BNM Institute Of Technology 2023-27-CSE-CS.No: 3 Exp. Name: Eldest of three Date: 2024-03-22
Ina classtoom, there are three students of varying ages. The teacher, who is responsible for the class, has a
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
a,b, © = Ant(input()), intCinput()), int(input())
print(a 1f (arb and arc) else b if (b>a and b>c) else c)
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
12
14
3
1
Test Case - 2
User Output
u
43
23
43
Test Case - 3
User Output
4
19
7
19
23CSC25_ Page No: 3
1D:
BNM Institute Of Technology 2023-27-CSE-CS.No: 4 Exp. Name: Factorial Calculator Date: 2024-03-22
Aim:
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.
def calculate_factorial (nunber)
return number if numberc=1 else nunber*calculate_factorial(number-1)
user_number = int (input())
factorial_result = calculate_factorial(user_nunber)
print (factorial_result)
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
10
3628800
Test Case - 2
User Output
6
72
23CSC25_ Page No:4
ID:
BNM Institute Of Technology _2023-27-CSE-CS.No: 5 Exp. Name: Fibonacci series. Date: 2024-03-22
‘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.
‘As 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
fib = lambda n : nif n c= 1 else (Fib(n-1) + #4b(n-2))
print(*[#Ib(1) for 4 in range(int(input()))], sep =" *, end = * *)
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
a
@1i2
Test Case - 2
User Output
10
@1123581321 34
23CSC25_ Page No: 5
ID:
BNM Institute Of Technology 2023-27-CSE-CS.No: 6 Exp. Name: Binary Coded Decimat Date: 2024-03-23
Aim:
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 isthe integer.
Output format:
The output is the BCD representation of the given integer.
Source Code:
bei
y
d= {'@': e000", '1': ‘oee1", '2': ‘oe1e", '3': ‘eoI1", ‘4': ‘e1e0",
‘ese’, "7": ‘eta1", ‘100@', *9": ‘1001'}
print("'.Join(d[i] for i in input()))
e101",
in Results - All test cases have succeeded!
Test Case - 1
User Output
15
eeeieie1
Test Case -2
User Output
253
eei9eie1e0i1
23CSC25_ Page No: 6
1D:
BNM Institute Of Technology 2023-27-CSE-CS.No: 7 Exp. Name: Store the marks in the dictionary Date: 2024-03-22
Aim:
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 for all N students, the program will store it in 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 Cod
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:
795
Nane_of student
Siraj
Marks of student 3:
89.2
‘(Clohn": 78.5, “Daniel's 79.5, "Siraj": 89.2)
Test Case -2
User Output
5
Nane of student 1
23CSC25_ Page No: 7
1D:
BNM Institute Of Technology 2023-27-CSE-CSwathi
Marks of student 1:
90.1
Nane_oF student 2
Sangeetha
Marks of student 2:
90.2
Nane_of student 3:
Samatha
Marks of student 3:
90.23
Nane of student 4
‘Aanya
Marks of student
925
Nane_ oF student 5:
Anvith
Marks of student
93.5
{(Swathi": 90.4, Sangeetha’: 90.2, “Sonatha': 90.23, “Aanya': 92.5, “Anvith': 93.5)
23CSC25_ Page No:8
1D:
BNM Institute Of Technology 2023-27-CSE-CS.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 Code:
wordsarrangement .py
List, key = input().split(',"), input()
word_count = [(word.count(key), word) for word in List]
print([woré for count, word in sorted(word_count, reverse = True)])
in Results - All test cases have succeeded!
Test Case - 1
User Output
no bun,bug bun bug bun bug bug.bunny
bug.buggy bug bug buggy
bug
[buggy bug bug buggy", “bug bun bug bun bug bug’, “bunny bug", “no bun")
Test Case -2
User Output
‘one one two,two three two two two,one one
‘one two, three four
cone.
[fone one one two", ‘one one two’, "two three two two two’, ° three four’)
23CSC25_ Page No:9
1D:
BNM Institute Of Technology 2023-27-CSE-CS.No: 9 Exp. Name: Frequency of the number Date: 2024-03-22
Aim:
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 is the 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
4-0
[d.update({4: (d.get(4, @)+1)}) for 4 in map(int, Anput()-split(’,"))]
print(d)
Execution Results - all test cases have succeeded!
Test Case - 1
User Output
pre GPEPE Peer!
(4 2 5, 3: 5)
Test Case - 2
User Output
1,1,1,222,22,22,22,33,33,3,3,33,33,3
(1: 3, 222: 1, 22: 3, 33: 4, 3}
Test Case - 3
User Output
3344, 55,66,77,88,11,22,22,33
(G32, 44: 4, 55: 4, 66: 1, 77: 1, 8: 1, Wd, sD
ID: 23CSC25__ Page No: 10
BNM Institute Of Technology 2023-27-CSE-CS.No: 10 Exp. Name: College Fest Fun Game Registration Date: 2024-03-22
Aim:
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 a member 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 lis, 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 ifthe token number is found otherwise print “Not found”
Note:
Assume there are no duplicates in the list.
Source Code:
festregister.py
1, m= input(), input()
print(1-split().index(n) if n in 1 else "Not found”)
Execution Results - all test cases have succeeded!
Test Case - 1
User Output
1234567
5
a
Test Case - 2
User Output
23131412791
18
Not found
ID: 23CSC25_ Page No: 11
BNM Institute Of Technology 2023-27-CSE-CS.No: 11 Exp. Name: Celestial Celebration Planner Date: 2024-03-22
Aim:
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
‘a pytamid-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 starry 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 "Invalid rows’
Note: For simplicity, the driver code has already been provided
Source Cod
CelestialPlanner.py
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 _name, main”
run_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)
n= int (input())
print("Invalid rows” if (n<=@ or n>2@) else print_pyramid(n, 1))
in Results - All test cases have succeeded!
Test Case - 1
User Output
ID: 23CSC25_ Page No: 12
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: 13
BNM Institute Of Technology 2023-27-CSE-CS.No: 14 Exp. Name: Binary to decimal Date: 2024-03-25
Aim:
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:
If the input is not a valid binary number, display the result as “Invalid’
Source Code
bintodecimal.py
a = input()
print( (sum((2**j)*i for J, i in enumerate(list(map(int, list(a)))[::-1])) ) if all(
for i in a) else “Invalid")
In Results - All test cases have succeeded!
Test Case - 1
User Output
1011
ry
Test Case -2
User Output
1000001
a
Test Case - 3
User Output
10256.
Invalid
ID: 23CSC25_ Page No: 14
BNM Institute Of Technology 2023-27-CSE-CS.No: 15 Exp. Name: Length of the string Date: 2024-03-25
Aim:
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
4
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(1en(ste1))
print(1en(**.join(strt.split())))
asinput()
Length(a)
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
Code tantra
14
10
Test Case - 2
ID: 23CSC25_ Page No: 15
BNM Institute Of Technology 2023-27-CSE-C‘Arguments.
User Output
23
LON abe | $29S3EZ ‘al D°BSI-L2-EZ0Z) ABojouyral JO aIMINSU| WES.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
ame 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, if the 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().split()
print(a[@] if len(a)
Lelse '.'.join({a[i]{@] for i in range(len(a)-1)] + [al-1]]))
Execution Results - all test cases have succeeded!
Test Case - 1
User Output
John William Smith
D.W.Smith
Test Case -2
User Output
George
George
ID: 23CSC25_ Page No: 17
BNM Institute Of Technology 2023-27-CSE-CExp. Name: Arha’s Birthday Mystery Date: 2024-03-25
Ain
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
cal = calendar. TextCalendar(calendar SUNDAY)
print(cal.formatyear(int(input()), 2, 1, 1, 3))
colunn width - 2
Lines per week - 1
spaces between each month - 1
months per counn - 3
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
2001
2001
Danuary Feoruary warch
Su Mo Tu We Th Fr Sa_Su Mo Tu We Th Fr Sa_Su No Tu We Th Fr Sa
223456 123 123
7@ 9s 4567891 45678 910
14 15 16 17 18 19 20 11 12 43 14 15 16 17 11 12 43 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 June
Tu We Th Fr Sa_Su Mo Tu We Th Fr Sa_Su Mo Tu We Th Fr Sa
7234567 12345 1
a owiuwim 678 92 345678
15 16 17 18 19 26 21_13 14 15 16 17 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
29:30 27 28 29:30 31 24 25 26 27 28 29 30
July ‘August September,
Su Yo Tu We Th Fr Sa_Su Mo Tu We Th Fr Sa_Su No Tu We Th Fr Sa
2
2
su
Mo
2
2
34567 1234 1
wii 567 8 9ti 2345 6
15 16 17 18 19 20 21 12 13 14 15 1617 18 9 10 11 12 13 14 15
ID: 23CSC25__ Page No: 18
BNM Institute Of Technology 2023-27-CSE-C2
3
24 25 26
27
28
Fr)
20
2a 22 23
24
a
16
v7
18 19 20
2
22,
29)
30
31
26
27
28 29 30
Br
23,
24
25 26 27
28
29)
30
October
Novenber
December
su
Tu We Th
Fe
sa
Tu We Th
sa
su
Tu We Th
Fe
sa
23 4
1
9 16 11
12
Fy
Gurme!
918
45 6
14
16 17 18
19
20
ry
12
13 14 15,
16
7
9 18
i112 13,
14
15
2
23 24 25
26
27
Fr
19
20 21 22
23
28
16
7
18 19 20
21
2
28
30 31
25
26
27 28 29,
38
23
24
25 26 27
28
29)
30
31
Test Case - 2
User Output
2005)
2005,
January
February
March
Su
Tu we Th
Fr
sa
su
Tu we Th
Fr
sa
su
Tu we Th
Fe
Sa
Turon)
cae)
45 6
e910
a
2
e910
ry
2
9 10
11213
1
15
3
14
45 16 17,
18
19
a
14
15 16 17
18
19
16
v7
18 19 20
21
2
20
2
22 23 24
25
26
20
2
22 23 24
25
26
2
24
25 26 27
28
29
27
7
28
29 30 31
30
3
‘april
May
June
su
Tu we Th
sa
su
Tu we Th
Fr
sa
su
No
Tu we Th
Fe
Sa
aaa
aa
5 67
10 11 12,
3
14
@
789
10
ry
Fr
Ft
21314
a5
16
15,
17 18 19
28
2
2
2B
14 15 16
a7,
18
7
18
19 20 21
22
23
22
24 25 26
27
28
Fr
20
21 22 23
24
25
2
25
26 27 28
29
30
29
31
26
27
28 29 30
suly
August
Septenber,
su
Tu we Th
Fr
sa
su
Tu we Th
Fr
sa
su
No
Tu we Th
Fe
sa
234
1
Suen
wo] |F
9 10 11
2
a
5
en7ee
10
10
Fr
21314
15
16
1
16 17 18
19
20
My
2
13 14 15
16,
7
7
18
19 20 21
22
23
2
22
23 24 25
26
7
18
19
20 21 22
23
24
28
25
26 27 28
29
30
28
29
30 22
25
26
27 28 29
38
3
october
Novenber
December
su
Tu we Th
Fr
sa
su
Tu we Th
Fr
sa
su
Tu we Th
Fe
sa
123
1
456
2 910
Fry
2
67 8
10
918
FrErETy
15
3
14
a5 16 17
18
19
My
2
1B 1415
16
7
16
7
18 19 28
2
22
28
2
22 23 28
25
26
18
19
20 21 22
2
2a
23
28
25 26 27
28
23)
27,
28
29 30
25
26
27 28 29
30)
3
38
31
ID: 23CSC25__ Page No: 19
BNM Institute Of Technology 2023-27-CSE-CS.No: 18 Exp. Name: Line in a file Date: 2024-03-25
Aim:
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 fie for a line
starting with the specified character and prints out the book title if found. If no book tite 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 = input(), input()
with open(file) as f:
new = [1 for 4 in f.readlines() if i[@] == key]
print(new[@] if new else "Not found")
file1.txt
The Power of Habit
Sapiens: A Brief History of Humankind
Becoming
Educated
The Inmortal 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
Execution Results - all test cases have succeeded!
Test Case - 1
User Output
ID: 23CSC25__ Page No: 20
BNM Institute Of Technology 2023-27-CSE-Cfilet txt
s
Sapiens: A Brief History of Hunankind
Test Case - 2
User Output
filet tet
F
Not found
ID: 23CSC25_ Page No: 21
BNM Institute Of Technology 2023-27-CSE-CS.No: 19 Exp. Name: Display the contents of the file Date: 2024-03-25
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.
‘As 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 fie ifthe file exists otherwise print "File does not exist”
Source Code:
file
put ()
with open(file) asf:
print(*[1 for i in [i{@s-a] if a[-1] =
f.readlines()]], sep = ‘\n')
except FilellotFoundError as e:
print("File does not exist")
"\n" else i for i in
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
The themes of love and friendship in literature
The impact of technology on storytelling
Exploring dystopian worlds in fletion
‘Analyzing unreliable narrators in novels
The role of humor in literature
Execution Results - All test cases have succeeded!
Test Case - 1
User Output
ID: 23CSC25__ Page No: 22
BNM Institute Of Technology 2023-27-CSE-Cfilet 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.txt
File does not exist
ID: 23CSC25_ Page No: 23
BNM Institute Of Technology 2023-27-CSE-CExp. Name: File Eligibility for Submission Date: 2024-03-25
Ait
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's 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 fil, 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 Cod
abstract. py
file = input()
try:
with open(File) as f:
List = list¢f.read())
L = len(List)
print(f"eligible\nTotal characters:{L}" if L<=250 else f"not eligible\ntotal
characters:{L}")
except FilellotfoundError as e:
print(“file does not exist")
filei.txt
This paper explores a relatively less popular source of clean energy.
An application is proposed for the same, in which a speaker and a 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 DC for
charging the battery and then invents DC to AC for powering the electric gadgets.
file3.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.
filed.txt
ID: 23CSC25_ Page No: 24
BNM Institute Of Technology 2023-27-CSE-CWhen a fire breaks out, time is of the essence. Prompt measures need to be taken to evacuate
‘the trapped people and contain the fine 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 autonated Fire Detection and Alarm System is equipped with a temperature sensor
and 2 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 characters:403,
Test Case - 3
User Output
file.txt
File does not exist
ID: 23CSC25__ Page No: 25
BNM Institute Of Technology 2023-27-CSE-CExp. Name: Check whether the point lies inside or
S.No: 21
° ‘on the boundary of a circle
Date: 2024-03-25
im:
‘As 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’ radius.
3. Write a function named point in circle that takes a Circle object and a Point object as arguments and
returns True if the 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
selfy = y
def point_in_circle(eircle, point)
return ((((point.x - circle.centre{@])*#2)+((point.y - circle.centre(1])**2))**
(1/2) <= circle.radius
center_x = float(input("x-coordinate of the circle center:
center_y = float(input("y-coordinate of the circle center:
: Circle radius
Float (input(*Radius of the circle: "))
# Inpu
radius
4 Input: Point coordinates
point_x = float(input("x-coordinate of the point: "))
point_y = float(input("y-coordinate of the point: “))
circle = Circle(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))
Execution Results - all test cases have succeeded!
Test Case - 1
ID: 23CSC25__ Page No: 26
BNM Institute Of Technology 2023-27-CSE-CUser Output
xcoondinate of the circle center:
0
y-coordinate of the circle center:
0
Radius of the circle:
5
x-coordinate of the point
3
y-coordinate of the point
4
Ts the point inside or on the boundary of the circle? True
Test Case - 2
User Output
x-coordinate of the circle center:
0
y-coordinate of the circle center
0
Radius of the circle:
5
xcoordinate of the point
6
y-coordinate of the point
0
Ts the point inside or on the boundary of the circle? False
ID: 23CSC25_ Page No: 27
BNM Institute Of Technology 2023-27-CSE-CS.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 ArcLength class, define a method named ealeulate_arc length that calculates the arc length using
the formula:
+ arclength=radius xangle(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 Cod
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_arc_length()
print("ane length:", round(are_length, 2))
Execution Results - all test cases have succeeded!
Test Case - 1
User Output
radius:
5
‘angle (in degrees):
45
fare length: 3.93
Test Case -2
ID: 23CSC25__ Page No: 28
BNM Institute Of Technology 2023-27-CSE-C62:0N a6eg | $2383€2 ‘ai
User Output
Padus:
10
‘angle (in degrees)
90
‘are length: 15.72
D-BSI-L2-EZ0Z) ABojouy>ay JO aIMsU| WEExp. Name: Non-Vowel Counter Date: 2024-03-25
Ait
‘To get an internship in CodeTantra you have been given a task to create a Python class NonVewelCounter 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, ¢, 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 NonVouelCounter class based on the given specifications,
Source Cod
NonVowelCounter.py
class NonVowelCounter:
def _init_(self):
self.string
def setString(self, string)
self.string = string
def countNonVowels (self):
return sum(1 for i in list(self.string) if 1 not in ‘aelouAeTOU')
Anput_string = input()
counter = NonVowelCounter()
counter. setString(input_string)
result = counter. countNonVowels()
print(result)
Execution Results - all test cases have succeeded!
Test Case - 1
User Output
Hello World!
3
ID: 23CSC25__ Page No: 30
BNM Institute Of Technology 2023-27-CSE-CLEON aBeg | S2583€2 ‘al
Test Case -2
User Output
‘AEIOU also considered as vowels right?
23
D°BSI-L2-EZ0Z)_ABojouy>al Jo aIMNsU| WINES.No: 24 Exp. Name: Count the magical words Date: 2024-03-25
Aim:
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
Output Format:
‘The output is an integer representing the number of magical words in the given string,
‘Source Code:
MagicalWordsCount.py
class MagicalWordscount:
def count_magical_words(self, L)
return sum(1 for i in L if (any(j.isupper() for j in list(i)) and
any(j.islower() for j in list(i)) and any(j.isdigit() for j in list(i))))
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 1
2
Test Case - 2
User Output
Hello World 123
@
ID: 23CSC25__ Page No: 32
BNM Institute Of Technology 2023-27-CSE-CS.No: 25 Exp. Name: Compound Interest Calculation Date: 2024-03-25
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 C1
+ 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 ine 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 Code
InterestCalculation. py
class cr
def _init_(self, p, r, t):
self.p = p
self.r =r
self.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
ps ry t = [float(i) for 4 in input().split())
T= C1(p, r, t)
print(#"Total Interest:
{round(TI.interest(), 2)}\nTotal Amount: {round(TI.totals(), 2)}")
“op, 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))
ID: 23¢SC25__ Page No: 33
BNM Institute Of Technology 2023-27-CSE-CExecution Results - all test cases have succeeded!
Test Case - 1
User Output
10005 5,
Total interest: 276.28
Total Amount: 1276.28
Test Case - 2
User Output
50000 6 1.5
Total Interest: 4566.84
Total Amount: 54566.84
Test Case - 3
User Output
40000 61
Total Interest: 2400.0
Total Anount: 42400.0
ID: 23CSC25__ Page No: 34
BNM Institute Of Technology 2023-27-CSE-CS.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 ttle 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 isa string representing the new title to be set,
The fourth line isa 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: 35
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_euthor = input().strip()
new_title = input().strip()
new_author = input().strip()
4 Create an instance of Book
book = Book’
1_title, initial_author)
# Display initial title and author
print(f'Initial Title: (book.get_title()}')
print(F*Initial Author: {book.get_author()}")
4H Set new title and author
book. set_title(new title)
book. set_author(new_author)
# Display new title and author
print(f'New Title: (book.get_title()}")
print(#'New Author: {book .get_author()}*)
Execution Results - all test cases have succeeded!
Test Case - 1
User Output
Harry Potter
JK. Rowling
‘The Hobbit
J.RR Tolkien
Initial Title: Harry Potter
Initial Author: 3. K. Rowling
New Title: The Hobbit
New Author: J. R. R. Tolkien
ID: 23CSC25__ Page No: 36
BNM Institute Of Technology 2023-27-CSE-CTest Case -2
User Output
‘The Da Vinci Code
Dan Brown
‘The Catcher in the Rye
1D Salinger
Initial Title: The Da Vinci Code
Initial Author: Dan Brown
New Title: The Catcher in the Rye
New Author: 9.0 Salinger
ID: 23CSC25__ Page No: 37
BNM Institute Of Technology 2023-27-CSE-CExp. Name: Fee Calculator Date: 2024-03-25
Aim:
‘To get an internship in CodeTantra you have been given a task to create a Python class Feecaleutater according
to the given specifications:
7. Implement a method setdetaits 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 a float value representing the total fee of the student.
Your task is to implement the Feecateulator class based on the given specifications.
Source Code:
Feecalculator.py
class FeeCalculato
def _init_(self):
self.name
self.rollno = @
self.fee = 0
self.percentage = @
def SetDetails(self, name, rollno, fee, percentage):
self.name = nane
self.rollno = rollno
self.fee = fee
self.percentage = percentage
def TotalFee(self)
return self.feet1.2 if self.percentagec=s@ else self.fee*1.15 if
else self.fee
self.percentage
input ()
rollnosint (input())
fee=int(input())
percentage=float(input())
student1 = FeeCalculator()
student. SetDetails(name,rolno, fee, percentage)
print(student2.TotalFee())
ID: 23CSC25__ Page No: 38
BNM Institute Of Technology 2023-27-CSE-CExecution 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.
20080
Test Case - 3
User Output
Jhansi
191844
17000
48.95
20400.0
ID: 23CSC25__ Page No: 39
2023-27-CSE-C
BNM Institute Of Technology