0% found this document useful (0 votes)
67 views8 pages

CAT 2 Question Bank

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views8 pages

CAT 2 Question Bank

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

CONTINUOUS ASSESSMENT TEST – 2

Regulations R 2023
Department of Information Technology
First Year / First Semester
231GES104T – PROBLEM SOLVING THROUGH PYTHON PROGRAMMING
CO1: Solve problems using algorithms, flowchart and pseudocode.
CO2: Use python conditional and iteration statements for problem solving
CO3: Apply strings and user defined functions in python programming.
CO4: Choose appropriate python data structures for real time applications
CO5: Develop Python code to manipulate data using file and exception-handling

Unit – III STRINGS (1/2 unit)

CO’s Bloom’s
Q.No Questions
Level
PART A
1. What will be the output of print(str[2:5]) if str=’hello world!’? CO3 K2
2. Python string is immutable. Justify with an example. CO3 K2
3. Let list=[‘a’,’b’,’c’,’d’,’e’]. Find a) list[1:3] b) list[:4] c) list[::] CO3 K2
Write a python program to print an Abecedarian series of given
4. CO3 K3
strings.
5. Write an example for string traversal. CO3 K2
6. Write a program to reverse a given string. CO3 K2
7. Write the usage of capitalize ( ) and title( ) methods in strings CO3 K2
Write a python program to use format sequence while printing a
8. CO3 K2
string
Write a python program to append a string to another using +=
9. CO3 K3
operator
Write a python program to print the string in reverse order thereby
10. CO3 K3
skipping every third character
11. Explain string comparison operators using examples. CO3 K1
Write a loop to count the number of occurrences of the letter ‘a’ in
12. CO3 K3
the string “Data analysis is amazing”
13. What do the ord() and chr() functions return with examples? CO3 K2
What will the following code print?
text=”Banana”
14. for i in range(len(text): CO3 K2
if text[i] == ‘a’
print(i)
Write a function to get the first half of a specified string of even
15. CO3 K3
length.
Write a Python program to count how many times a given substring
occurs in a string, ignoring case. Input Example as follows:
16. String: "Python is great. I love Python programming because Python CO3 K3
is versatile."
Substring: "python"
Write a program to remove the leading and trailing spaces from
17. CO3 K3
string
18. Write a python program to remove the nth index character from non- CO3 K3
empty string
Write a program to find words which are greater than given length k
19. CO3 K3
in a given string.
20. Write a python program to set indentation of the first line. CO3 K3
Write a python program to display a string in left, right and center
21. CO3 K3
aligned of width 10
Write a Python program to right rotate the characters in the string by
22. CO3 K3
2 times. Input: study, Expected output: dystu

CO’s Bloom’s
Q.No Questions
Level
Part – B
Develop two Python functions to check the given string is
palindrome or not by using recursion and symmetrical or not
respectively. Use these functions in a Python program to check the
1. CO3 K4
given string for the same.
Input Example: KhoKho
Output Example: Symmetrical and not Palindrom
A company wants to generate usernames for its employees based on
their full names. The rules for generating usernames are:
1. Convert the full name to lowercase.
2. Use the first letter of the first name followed by the last
name, without spaces.
2. 3. If the username exceeds 15 characters, truncate it to 15 char- CO3 K5
acters.
Develop a Python program to generate usernames for a given list of
employee full names.
Your Input Strings: [“Rohit Sharma”,”Virat Kohli”,”Sachin Ramesh
Tendulkar”]
Write a Python function to reverse a string, but only reverse the
words with an even number of characters. Words with an odd
3. number of characters should remain in the same order. CO3 K4
Input: “"Python is fun and amazing"”
Output: "nohtyP si fun and amazing"
Illustrate the various built-in string handling functions with suitable
4. CO3 K4
examples
Design a python program to create the following pattern for the
number of rows given.
A
5. AB CO3 K4
ABC
ABCD
ABCDE
Write a python program that accepts a string from user and count the
6. number of vowel present in it and redisplays the same string after CO3 K4
removing vowels from it.
Write a program that finds whether a given character is present in a
7. string or not. In case it is present it prints the index at which it is CO3 K4
present. Do not use built-in find function to search the character
Demonstrate the various slice operations on string object using all
8. CO3 K4
possible positive and negative indexes.
An organization collects feedback from its employees in the form of
a paragraph. The feedback is stored as a string in Python. Write a
program to analyze the feedback string.
Input: "The work environment is good. The management is
supportive. The work-life balance is excellent."
9. Tasks: CO3 K4
 Count the number of words in the feedback string.
 Identify and print the most frequently used word. If there is a tie,
display all the tied words in alphabetical order.
 Remove any extra spaces (leading, trailing, or multiple spaces
between words) in the string and return the cleaned version.
A retail company stores product names and prices in a comma-sepa-
rated string format, but the prices need to be formatted properly. De-
velop a Python program to:
1. Extract product names and prices from the string.
10. 2. Format the prices to two decimal places. CO3 K5
3. Combine the product names and formatted prices into a new
string, separated by a colon (:).
Input: "Apple,120.5,Banana,45,Cherry,150.78"
Output: "Apple:120.50, Banana:45.00, Cherry:150.78"
Write a program to append a string to another string without using
11. CO3 K4
+=operator
Write a Python program that replaces all but the last five characters
of a string with "*" and returns the modified string.
12. CO3 K4
Input String: 12345abcdef
Output String: ******bcdef

CO’s Bloom’s
Q.No Questions
Level
Part c
Develop a Python program that generates a hashtag from a given
sentence by analysing the following rules to form a hashtag.
1. It starts with a #.
2. Each word in the sentence is capitalized and concatenated without
spaces.
1. CO3 K5
3. If the final hashtag exceeds 30 characters, return "Hashtag too
long!".
4. If the input sentence is empty, return "Invalid input!".
Example: Input string:”I like python prog”
Output:#ILikePythonProg
Develop a Python program to read two strings and swap the first two
characters of each string.
2. CO3 K5
Input : 'abc', 'xyz'
Expected Result : 'xyc abz'
3 Develop a Python program to add 'ing' at the end of a given string CO3 K5
(length should be at least 3). If the given string already ends with
'ing' then add 'ly' instead. If the string length of the given string is
less than 3, leave it unchanged.
Input String : 'abc'
Expected Result : 'abcing'
Input String : 'string'
Expected Result : 'stringly'

Unit – IV LIST, TUPLE AND DICTIONARIES

CO’s Bloom’s
Q.No Questions
Level
PART A
1. Differentiate tuple and list in python. CO4 K1
2. Let list = [’a’, ’b’, ’c’, ’d’, ’e’, ’f’]. Find a) list[1:3] b) t[:4] c) t[3:] CO4 K2
3. State the difference between lists and dictionary CO4 K2
4. What is List mutability in Python? Give an example. CO4 K2
5. What is aliasing in list? Give an example. CO4 K1
Write a Python statement to add a new product "Smartwatch": 250 to
6. the dictionary: products = {"Laptop": 800, "Tablet": 300, "Phone": CO4 K3
500}
7. Define cloning a list with example CO4 K1
8. Explain list as parameters to a function with an example. CO4 K2
9. Write a program in Python to delete first element from a list. CO4 K2
Write a Python function that takes a list of numbers and returns a
10. CO4 K2
new list containing only the odd numbers .
11. What is the benefit of using tuple assignment in Python? CO4 K1
12. Define dictionary with an example. CO4 K1
How to create a list in python? Illustrate the use of negative indexing
13. CO4 K2
of list with example?
14. What is the difference between indexing and slicing? CO4 K2
Write a Python program to check if the length of a tuple is greater
15. CO4
than 5. data = (1, 2, 3, 4, 5, 6) K2
Given a list of employee salaries: [35000, 42000, 50000, 28000].
16. Write a Python code to increase each salary by 10% and return the CO4 K3
updated list.
17. What the difference is between append and extend methods in list. CO4 K2
A dictionary contains daily sales data:
sales = {"Monday" : 450, "Tuesday": 550, "Wednesday": 400}
18. CO4 K2
Write a Python statement to find and print the day with the highest
sales.
Write a Python function that takes a list of numbers and returns a
new list containing only the odd numbers.
19. CO4 K3
Input Example: [2, 5, 8, 9, 11]
Output Example: [5, 9, 11]
Given a tuple of product prices (130,125,100,110). Write a Python
20. program to convert tuple into a list and add a new price 200 to the CO4 K2
list.
You have the dictionary:
inventory = {"apples": 50, "bananas": 30, "cherries": 20}
21. CO4 K2
Write a Python statement to remove the key "bananas" from the
dictionary.
CO’s Bloom’s
Q.No Questions
Level
Part – B
1. Illustrate about the various list built-in methods with examples.. CO4 K4
Illustrate list comprehension in detail and assume a list l = [1, 2, 3, 4,
2. 5, 6]. Write a list comprehension to right rotate the elements by k CO4 K4
times.
Is it possible to return tuple as values? Justify your answer with an
3. CO4 K4
example.
4. Illustrate the dictionary methods with suitable examples. CO4 K4
Illustrate the various tuple operations and built-in functions with
5. CO4 K4
suitable examples
A library maintains a collection of books, where each book is repre-
sented as a tuple containing its title, author, and publication year.
Write a Python program to:
6. K4
1. Allow the user to search for a book by title. CO4
2. Display the details of all books by a specific author.
Find and display the most recent book in the collection.
An organization tracks employees' work hours using a tuple. Each el-
ement in the tuple represents the hours worked by an employee in a
week. Develop a Python program to:
1. Calculate the total hours worked by all employees.
7. CO4 K5
2. Identify employees who worked less than 40 hours (under-
performers).
3. Return the index of the employee who worked the maximum
hours.
Develop a program to track the temperatures of multiple cities using
a dictionary, where keys are city names, and values are lists of daily
temperatures. Perform the following:
1. Calculate the average temperature for each city.
2. Identify the city with the highest average temperature.
8. CO4 K5
3. Return a list of cities where the temperature dropped below
10°C on any day.
Input Value:
City_Temperatures = { "Delhi": [30, 32, 35, 31, 29], "Mumbai": [28,
29, 31, 30, 27], "Shimla": [5, 7, 10, 12, 6] }
A sales company stores daily sales data as a dictionary, where keys
are dates, and values are lists of product sales for that day. Write a
Python program to:
1. Calculate the total sales for each day.
9. 2. Identify the day with the highest sales. CO4 K4
3. Return the average sales across all days.
Input Values:
Sales_Data = { "2024-11-01": [150, 200, 100], "2024-11-02": [300,
250, 400], "2024-11-03": [500, 600] }
10. A voting system records votes as a tuple where each element is the CO4 K4
name of a candidate voted for. Write a program to:
1. Count the total votes received by each candidate.
2. Identify the candidate with the highest votes.
3. Check if there is a tie, and list the candidates in case of a tie.
Input Value: Votes = ("Veerabaghu", "Thara", " Veerabaghu ",
"Charlie", "Thara", " Veerabaghu ", "Thara")
A weather station records data for multiple cities, where each record
is a tuple in the format (city, date, temperature). Write a Python pro-
gram to:
11. 1. Find the average temperature for a specific city. CO4 K4
2. Identify the hottest temperature recorded and the city where it
occurred.
3. List all temperature records for a given date.
A grocery store maintains the prices of items in a dictionary. Write a
Python program to:
1. Calculate the total bill for a customer based on the quantities
12. CO4 K4
they purchase.
2. Add a new item to the price dictionary.
3. Display all items sorted by their price in ascending order.

CO’s Bloom’s
Q.No Questions
Level
Part c
A E-commerce website tracks user ratings using a list. Each rating is
an integer between 1 and 5. ratings = [5, 3, 4, 2, 5, 1, 3, 4, 5]
Develop a Python program to:
1. CO4 K5
1. Count the number of 5-star ratings.
2. Find the percentage of ratings that are 3-star or higher.
3. Display the ratings in ascending order without duplicates.
An expense tracker stores daily expenses in a dictionary where keys
are dates and values are lists of expenses for that day. Solve the fol-
lowing using a Python program.
1. Calculate the total expense for each day.
2. 2. Identify the day with the highest expense. CO4 K5
3. Calculate the overall average expense per day.
Input values:
expenses = { "2024-11-01": [200, 150, 100], "2024-11-02": [300,
400, 250], "2024-11-03": [50, 100] }
The weekly temperature of a city is stored in a tuple. Develop a
Python program to:
1. Find the maximum and minimum temperatures.
2. Determine the index of the highest temperature.
3. 3. Convert the tuple into a list and add the temperature for the CO4 K5
8th day.
Input values:
temperatures = (30, 32, 33, 31, 35, 34, 30)
New_Temperature = 36

Unit – V FILES, EXCEPTIONS

CO’s Bloom’s
Q.No Questions
Level
PART A
1. What is a module? Give an example. CO5 K1
2. What is a command line argument? CO5 K1
3. Write a python program that writes “Hello world” into a file. CO5 K2
4. Write a python program that counts the number of words in a file. CO5 K3
5. What are the two arguments taken by the open() function? CO5 K2
6. Write a Python file program to append data to an existing file CO5 K1
7. What is an exception? CO5 K1
What are the error messages that are displayed for the following
8. CO5 K2
exceptions?
9. Explain the two parts in an error message? CO5 K1
How do you handle the exception inside a program when you try to
10. CO5 K2
open a non- existent file?
11. How does try and execute work? CO5 K1
What is the function of raise statement in Python? Write its two
12. CO5 K1
arguments.
13. What are the two methods used in Python pickling? CO5 K1
Write a Python program that prompts the user to input an integer and
14. CO5 K1
raises a ValueError exception if the input is not a valid integer.
15. Define package with an example. CO5 K1
16. Write a Python program to write a list content to a file. CO5 K1
17. What is the special file that each package in Python must contain? CO5 K2
18. How do you delete a file in Python? CO5 K1
How do you use command line arguments to give input to the
19. CO5 K2
program?
Write a Python program to handle a ZeroDivisionError exception
20. CO5 K3
when dividing a number by zero.

CO’s Bloom’s
Q.No Questions
Level
Part – B
Write a Python function that copies a file by reading and writing up
1. CO5 K4
to 50 characters at a time.
Develop a Python program to analyse the count such as number of
2. CO5 K5
lines, words and characters in a text file.
3. Illustrate the use of command-line arguments with examples CO5 K4
Mention the commands and their syntax for the following: get
4. current directory, changing directory, list directories and files, make CO5 K4
a new directory, renaming and removing directory.
Implement stack operations using Python modules and analyse with
5. CO5 K5
sample data.
Develop a Program to get odd lines from a file and append them to
6. CO5 K4
separate file
Develop a Python file program to sort all the lines in a file as per line
7. CO5 K4
length size.
How does Python determine which exception block to execute if
8. multiple except blocks are present? Demonstrate the same with CO5 K4
examples.
How does Python handle exceptions using try, except, finally, and
9. CO5 K4
raise statements? Explain with suitable examples
What happens if you open a file in w mode that already exists? Write
10. CO5 K4
a Python program to take user input and save it to a text file.
Why is it important to close a file after use? How does the ‘with’
11. CO5 K4
statement simplify file handling?
Demonstrate how a finally block can be executed even if the try
12. CO5 K4
block raises an exception? Explain with an example.

CO’s Bloom’s
Q.No Questions
Level
Part c
Illustrate the different methods used for reading from and writing to
1. text files in Python, and how can you handle common issues such as CO5 K5
file not found errors and ensuring files are properly closed?
Develop a Python program that opens a file, analyse the handling of
the following exceptions.
2.  FileNotFoundError exception if the file does not exist. CO5 K5
 PermissionError exception if there is a permission issue.
UnicodeDecodeError exception if there is an encoding issue.

You might also like