DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Question Bank 2 AY 2024-25
Subject Code: BPLCK205B Subject: Introduction to Python Programming Date: 17/05/2025
Semester: 2 Module: 2 (2nd Half) & 3 Branch: CSE
Module – 2
BT
Q# Mod# CO# Questions Marks
L
Write a python program to read dictionary data and delete any given key entry in
the dictionary.
d = {'a':1,'b':2,'c':3,'d':4}
print("Initial dictionary")
print(d)
1. key=raw_input("Enter the key to delete(a-d):") 6M
2 2
3 if key in d:
del d[key]
else:
print("Key not found!")
exit(0)
print("Updated dictionary")
print(d)
Using string slicing operation write python program to reverse each word
in a given string (eg: input: “hello how are you”, output: “olleh woh era
uoy”) def reverse_string(str):
str1 = "" # Declaring empty string to store the reversed string
for i in str:
str1 = i + str1
return str1 # It will return the reverse string to the caller function
2. 8M
2 2 3 str = " hello how are you " # Given String
print("The original string is: ",str)
print("The reverse string is",reverse_string(str)) # Function call
Output:
('The original string is: ', ' hello how are you ')
('The reverse string is', ' olleh woh era uoy ')
Read a multi-digit number (as chars) from the console. Develop a program
3. 2 2 3 to print the frequency of each digit with suitable message. 6M
Ans : Lab Program 4
4. 2 2 2 Explain the following methods with a programming example:
(i) get() (ii) setdefault() (iii) items() 6M
Develop a program to print 10 most frequently appearing words present in
the string entered by the user. [Hint: Use dictionary with distinct words
5 2 2 3 and their frequency of occurrences. Sort the dictionary in the reverse order 8M
of frequency and display dictionary slice of first 10 items]
Ans : Lab program 5
6 2 2 1 List the merits of dictionary over list. 4M
7 2 2 2 Give a short note about pretty printing with suitable example 6M
8. 2 2 2 What is dictionary? Illustrate it with an example of the usage of nested
6M
dictionary.
9 2 2 3 Discuss the following Dictionary methods in Python with examples.
8M
(i)get() (ii) items() (iii)keys() (iv) values()
Develop a Python function called find_grade that takes a
10 2 2 3 student's name as input and returns their grade from the grades dictionary.
8M
If the name is not found,return "Not found." Use the following dictionary:
grades = {"Alice": "A", "Bob":"B", "Charlie": "C"}
Module – 3
CO
Q# Mod# BTL Questions Marks
#
1. 3 3 Discuss different paths of file system. 6M
2
2. Explain how to read specific lines from a file?. illustrate with python
3 3 6M
2 program.
3. 3 5 Write an algorithm for implement multi clipboard functionality 6M
2
4. 3 3 Discuss how lists would be written in the file and read from the file? 8M
3
What is raw string? Illustrate the following string methods with a
5. 3 3 3 programming example: 10M
i. upper() ii. center() iii. ljust() iv. endswith()
6. Explain Python string handling methods with examples:
3 3 2 10M
i. split() 11. endswith() iii. ljust() iv. center() v. lstrip()
7. Explain reading and saving python program variables using shelve module
3 3 2 6M
with suitable Python program.
8. 3 3 3 Develop a Python program to read and print the contents of a text file. 4M
9. Explain Python string handling methods with examples:
3 3 2 10M
i. join() ii. startswith() iii. rjust() iv. strip() v. lstrip()
10. Explain with suitable Python program segments:
3 3 2 5M
(i) os.path.basename() (ii)os.path.join().
11. Develop a Python program find the total size of all the files in the given
3 3 3 5M
directory
12. Illustrate with example opening of a file with open() function, reading the
3 3 2 12
content of the file with read() and writing to files with write().
13. Explain the steps involved in adding bullets to Wiki -Markup. Support with
3 3 2 10
appropriate code.
Develop a program to sort the contents of a text file and write the sorted
14. contents into a separate text file. [ Use strip( ), len ( ) , list methods sort ( ),
3 3 3 10
append and file methods open( ), readlines( ), and write( ) ]
Ans: Lab pgm 6
Discuss the following methods of os module
(i) chdir()
(ii) rmdir()
15. 3 3 3 10
(iii) walk()
(iv) listdir()
(v) getcwd()
List out all the isX String methods in python. Explain with an example for
16. 3 3 3 10
each method
Course Outcomes:
CO1 Demonstrate proficiency in handling loops and creation of functions.
CO2 Identify the methods to create and manipulate lists, tuples and dictionaries.
CO3 Develop programs for string processing and file organization
CO4 Interpret the concepts of Object-Oriented Programming as used in Python.