GE3151 Python QB
GE3151 Python QB
S.No Question K CO
Level
1 Define an algorithm and explain its significance in computing. K1 CO1
2 List the difference between pseudo code and flow charts? K1 CO1
3 K1 CO1
Explain the concept of a state in the context of algorithms.
4 K1 CO1
Define the control flow is in algorithm design.
5 K1 CO1
Define a function in programming? Give an example.
6 K1 CO1
How does iteration differ from recursion?
7 K1 CO1
Write a pseudo code to find the maximum number in a list.
8 K1 CO1
Create a simple flowchart for a login process.
9 Define the term 'algorithmic problem solving'? K1 CO1
10 K1 CO1
Define the role of control flow statements in an algorithm.
11 K1 CO1
Define the term 'state' with an example from a sorting algorithm.
12 K1 CO1
How do you represent algorithms in a programming language?
13 K1 CO1
Write a pseudo code to sum all the elements of a list.
14 K1 CO1
What is a base case in recursion?
15 K1 CO1
Create a flowchart to calculate the factorial of a number.
16 K1 CO1
Define the significance of pseudo code in algorithm design?
17 How do functions help in breaking down complex problems? K1 CO1
18 K1 CO1
List the iterative approach to solve the problem of finding the minimum in a list.
19 K1 CO1
Write a pseudo code for a binary search algorithm.
20 K1 CO1
List the advantages of using recursion in algorithms?
21 How would you represent the algorithm for inserting an element in a sorted list using a K1 CO1
flowchart?
22 K1 CO1
Define a real-world scenario where iteration is preferred over recursion.
23 K1 CO1
Write the purpose of using flowcharts in algorithm development?
24 Write a pseudo code for calculating the sum of numbers from 1 to n. K1 CO1
25 K1 CO1
define the meaning by 'algorithmic efficiency'?
26 K1 CO1
How does recursion work in the context of the Towers of Hanoi problem?
27 K1 CO1
Write a pseudo code to check if a number is prime.
28 K1 CO1
Define the process of debugging an algorithm.
29 K1 CO1
Write the role of a function in modular programming?
30 K1 CO1
Create a flowchart to reverse a string.
S.No Question K CO
Level
1 Explain the steps involved in designing an algorithm. Illustrate with an example K2 CO1
algorithm.
2 Discuss the differences between pseudo code and flow charts in representing K2 CO1
algorithms. Provide examples.
3 Write a detailed pseudo code for the Towers of Hanoi problem and explain its recursive K2 CO1
nature.
4 Describe the concept of state in algorithms and provide an example of how it affects the K2 CO1
execution of an algorithm.
5 Write an algorithm (using pseudo code) to sort a list of integers using the insertion sort K2 CO1
technique.
6 Explain the concept of recursion with a pseudo code example for calculating Fibonacci K2 CO1
numbers.
7 Design a flowchart for an algorithm that inserts an element into a sorted list while K2 CO1
maintaining the sorted order.
8 Discuss the advantages and disadvantages of using iteration versus recursion with K2 CO1
appropriate examples.
9 Write pseudo code to solve the problem of guessing an integer number within a K2 CO1
specified range using binary search.
10 Create a comprehensive flowchart for the process of checking if a string is a K2 CO1
palindrome.
11 Illustrate the use of algorithmic problem-solving strategies with examples of solving K2 CO1
basic problems such as finding the maximum value in an array.
12 Describe the role of control flow structures in algorithms with examples of sequential, K2 CO1
selection, and iteration constructs.
13 Write a detailed pseudo code for a linear search algorithm and explain its time K2 CO1
complexity.
14 Design a flowchart for calculating the greatest common divisor (GCD) of two numbers K2 CO1
using the Euclidean algorithm.
15 Provide a detailed explanation of the recursive approach to the Towers of Hanoi K2 CO1
problem and its time complexity.
16 Discuss how pseudo code can be used to bridge the gap between algorithm design and K2 CO1
actual implementation in a programming language.
17 Write a pseudo code and provide a flowchart to demonstrate the process of reversing an K2 CO1
array of integers.
18 Explain the concept of algorithmic efficiency with examples of different sorting K2 CO1
algorithms.
19 K2 CO1
Create a pseudo code for a function that finds the nth largest element in an unsorted list.
20 K2 CO1
Discuss the importance of base cases in recursive algorithms with an example.
S.N Question K CO
o Level
1 Design an algorithm to solve the Towers of Hanoi problem. Include a step-by-step K3 CO1
explanation of the recursive approach, and write a detailed pseudocode for the algorithm.
Discuss the time complexity of your solution.
2 Implement the Towers of Hanoi algorithm in Python. Explain the key components of your K3 CO1
code, including the recursive function and the base case. Provide an example execution
with three disks and describe the moves required.
3 Write a detailed analysis of the Towers of Hanoi problem, including its recursive solution. K3 CO1
Compare it with an iterative solution (if applicable), and discuss the advantages and
disadvantages of each approach.
4 Create a flowchart to represent the Towers of Hanoi algorithm for solving the problem K3 CO1
with n disks. Explain how the flowchart reflects the recursive nature of the algorithm and
how it manages the control flow.
5 Develop a pseudocode algorithm for finding the minimum element in an unsorted list. K3 CO1
Discuss how this algorithm can be implemented using iteration and recursion. Compare
the efficiency of both methods in terms of time complexity.
6 Explain how you would modify the Towers of Hanoi problem to handle additional K3 CO1
constraints, such as limiting the number of moves or introducing a third peg that can only
hold a specific number of disks. Provide an algorithm and discuss the implications on
complexity.
7 Write a Python function to insert a card into a sorted list of cards while maintaining the K3 CO1
sorted order. Describe how your algorithm ensures the list remains sorted and the time
complexity of the insertion operation.
8 Discuss the process of guessing an integer number in a range using a binary search K3 CO1
approach. Provide pseudocode for the binary search algorithm, and explain how it differs
from a linear search in terms of efficiency.
9 Create a detailed flowchart for the algorithm to guess an integer number within a range K3 CO1
using binary search. Explain how the flowchart captures the iterative nature of the binary
search process and how it handles the control flow.
10 Design and analyze an algorithm to solve the problem of inserting an element into a sorted K3 CO1
list of integers. Provide pseudocode and discuss both iterative and recursive approaches.
Compare their efficiency in terms of time complexity and space complexity.
Python interpreter and interactive mode,debugging; values and types: int, float, boolean, string , and
list; variables, expressions, statements, tuple assignment, precedence of operators, comments;
Illustrative programs: exchange the values of two variables, circulate the values of n variables, distance
between two points.
PART-A (2 Marks)
S.No Question K CO
Level
1 K1 CO2
What is the Python interpreter and how is it used?
2 K1 CO2
Describe how to start the Python interactive mode.
3 K1 CO2
What is the purpose of the print() function in Python?
4 K1 CO2
How can you debug a Python program using print statements?
5 K1 CO2
Define the int type in Python with an example.
6 K1 CO2
Explain the float type in Python with a sample value.
7 K1 CO2
What does the bool type represent in Python? Provide an example.
8 K1 CO2
How do you declare a string in Python? Provide an example.
9 K1 CO2
What is a list in Python? Provide an example.
10 K1 CO2
How do you assign a value to a variable in Python?
11 K1 CO2
What is an expression in Python? Give an example.
12 K1 CO2
Define a statement in Python with an example.
13 K1 CO2
What is tuple assignment in Python? Give an example.
14 K1 CO2
Explain operator precedence with an example involving addition and multiplication.
15 K1 CO2
How do you write a single-line comment in Python?
16 K1 CO2
What is the purpose of multi-line comments in Python?
17 How can you swap the values of two variables in Python? K1 CO2
18 K1 CO2
Describe a simple debugging technique using the Python interactive mode.
19 K1 CO2
What is the difference between a list and a tuple in Python?
20 K4 CO2
How do you concatenate two strings in Python?
21 K5 CO2
What is the result of 5 + 2 * 3 in Python? Explain why.
22 K1 CO2
How do you access the first element of a list in Python?
23 K1 CO2
What is the output of True and False in Python?
24 K1 CO2
How do you create a comment block in Python?
25 K1 CO2
What is the output of the expression (2 + 3) * 4 in Python?
S.No Question K CO
Level
1 Explain the Python interactive mode and its advantages. Include a brief example of its K2 CO2
usage.
2 Discuss how to use the pdb module for debugging in Python. Provide a basic example K2 CO2
of setting a breakpoint.
3 K2 CO2
Write a Python program that demonstrates the use of int, float, bool, str, and list types.
4 Explain the concept of variables in Python with examples. How are variables different K2 CO2
from constants?
5 Write a Python function that swaps the values of two variables without using a K2 CO2
temporary variable. Provide a sample output.
6 Describe the operator precedence in Python. Illustrate with an example involving K2 CO2
multiple operators.
7 How do you write and use multi-line comments in Python? Provide a code snippet that K2 CO2
demonstrates their use.
8 Write a Python program that uses tuple assignment to initialize multiple variables in K2 CO2
one line.
9 Explain how to debug a Python program using print statements. Illustrate with a sample K2 CO2
code that has a logical error.
10 Write a Python function that circulates the values of n variables. Provide an example K2 CO2
and explain the output.
11 Discuss the differences between list and tuple in Python, including mutability and use K2 CO2
cases.
12 Create a Python program to calculate the distance between two points in a 2D plane K2 CO2
using the Euclidean formula.
13 Write a Python script that demonstrates the use of expressions with mixed data types K2 CO2
and explains the output.
14 Explain the concept of precedence of operators with an example that includes K2 CO2
arithmetic and comparison operators.
15 How do you handle comments in Python code? Explain with examples of both single- K2 CO2
line and multi-line comments.
16 Write a Python program to check if a given value is of type int, float, str, or bool and K2 CO2
print the type.
17 K2 CO2
Provide a code example that demonstrates tuple assignment and explain how it works.
18 Describe the role of comments in Python programming. How do comments help in K2 CO2
debugging?
19 Write a Python function that exchanges the values of two variables using arithmetic K2 CO2
operations. Provide an example of its output.
20 Discuss different methods to debug Python code and provide examples of their K2 CO2
application.
S.No Question K CO
Level
1 Write a detailed Python program that demonstrates variable assignment, types, and basic K3 CO2
operations. Explain each part of the code and its output.
2 Create a Python function to swap the values of two variables using the XOR bitwise K3 CO2
operator. Provide an explanation and example.
3 Write a Python program that circulates values among n variables, where n is provided K3 CO2
by the user. Explain the algorithm and provide sample output.
4 Develop a Python script to compute the distance between two points in a 2D plane. K3 CO2
Include comments explaining each step and a sample run of the script.
5 Explain operator precedence in Python with detailed examples. Provide a program that K3 CO2
illustrates how precedence affects the evaluation of expressions.
6 Create a comprehensive Python program that uses int, float, bool, str, and list. Describe K3 CO2
how each type is used and the output of the program.
7 Write a Python program to demonstrate debugging techniques using pdb. Explain how K3 CO2
the debugging process helps in identifying and fixing errors.
8 Provide a Python script that includes tuple assignment and demonstrates how to unpack K3 CO2
values into multiple variables. Explain the concept with examples.
9 Discuss how to effectively use comments in Python code. Write a program that uses K3 CO2
both single-line and multi-line comments, and explain their usage.
10 Write a detailed Python function to swap values between two variables using Python's K3 CO2
built-in capabilities. Include a discussion on the advantages of using Python's features
over manual methods
Conditionals:Boolean values and operators, conditional (if), alternative (if-else),chained conditional (if-elif-
else);Iteration: state, while, for, break, continue, pass; Fruitful functions: return values,parameters, local and
global scope, function composition, recursion; Strings: string slices,immutability, string functions and
methods, string module; Lists as arrays. 24 Illustrative programs: square root, gcd, exponentiation, sum an
array of numbers, linear search, binary search.
PART-A (2 Marks)
S.No Question K CO
Level
1 K1 CO3
What is the result of the following Boolean expression? True and (False or True)
2 K1 CO3
Explain the difference between if and if-else conditional statements.
3 K1 CO3
Write a one-line if statement that checks if a number x is greater than 10.
6 Write the output of the following code K1 CO3
x=5
if x < 10:
print("Less than 10")
else:
print("10 or more")
7 K1 CO3
Write the continue statement in a loop?
8 K1 CO3
How does the break statement affect a loop?
9 Write a simple while loop that prints numbers from 1 to 5. K1 CO3
10 K1 CO3
Define a for loop that iterates over the elements of a list.
11 K1 CO3
Define the difference between local and global variables in a function?
12 K1 CO3
Write the term 'string immutability'.
13 K1 CO3
How would you access the second character of the string "Hello"?
14 K1 CO3
How does recursion work in Python?
15 K1 CO3
Define the pass statement in Python?
16 K1 CO3
Define operation? ‘"Python"‘[1:4]
17 K1 CO3
How do you use the len() function on a list?
18 Write the following code print? K1 CO3
print("abc".upper())
19 K1 CO3
How do you concatenate two strings in Python?
20 K1 CO3
Define the purpose of the string module in Python?
21 K1 CO3
How can you convert a string to an integer in Python?
22 K1 CO3
List the difference between list.append() and list.extend()?
23 K1 CO3
How do you create a list of integers from 1 to 5 using a for loop?
24 K1 CO3
Write gcd stand for, and which Python function calculates it?
25 K1 CO3
Write a simple function that takes a number and returns its square.
26 List the output of the following code snippet? K1 CO#
x = 10
while x > 0:
x -= 1
if x == 5:
continue
print(x)
27 Define a tuple and how does it differ from a list? K1 CO3
S.N Question K CO
o Level
1 Write a comprehensive program that calculates the square root of a number using the K3 CO3
binary search method, and explain the steps involved.
2 Develop a full implementation of a binary search algorithm in Python with a description K3 CO3
of its time complexity.
3 Create a program to find all prime numbers in a given range and explain the Sieve of K3 CO3
Eratosthenes algorithm used.
4 Write a Python program that reads a list of numbers from the user, sorts the list, and K3 CO3
performs a binary search on the sorted list to find a user-specified number.
5 Design a function to solve the Tower of Hanoi problem using recursion, and explain the K3 CO3
recursive steps involved.
6 Implement a full example of a string manipulation program that demonstrates various K3 CO3
string methods such as strip(), strip(), replace(), and split().
7 Create a program that uses a while loop and a for loop to generate the Fibonacci sequence K3 CO3
up to a given number and explain the differences in their implementation.
8 Write a function to compute the Greatest Common Divisor (GCD) of multiple numbers K3 CO3
and explain how the function can be used to simplify fractions.
9 Develop a complete program that demonstrates how to use global and local variables K3 CO3
within nested functions and the impact of variable scope.
10 Design and implement a sorting algorithm, such as merge sort or quicksort, and explain its K3 CO3
working principle and time complexity.
Lists: list operations, list slices, list methods, list loop, mutability, aliasing, cloning lists, list parameters;
Tuples: tuple assignment, tuple as return value; Dictionaries: operations and methods; advanced list
processing - list comprehension; Illustrative programs: simple sorting, histogram, Students marks
statement, Retail bill preparation.
PART-A (2 Marks)
S.No Question K CO
Level
1 What is the result of the following list operation? my_list = [1, 2, 3]; my_list.append(4) K1 CO4
2 How would you access the third element of the list numbers = [10, 20, 30, 40, 50]? K1 CO4
3 What is the output of the following code snippet? K1 CO4
my_list = [1, 2, 3, 4]
print(my_list[1:3])
4 How do you remove an item from a list by index? K1 CO4
5 Explain the difference between list slicing and list indexing. K1 CO4
6 What does the list.sort() method do? K1 CO4
7 What is the output of the following code? K1 CO4
my_list = [1, 2, 3]
my_list.extend([4, 5])
print(my_list)
8 How can you check if an element exists in a list? K1 CO4
9 What will be the output of the following code snippet? K1 CO4
my_list = [1, 2, 3]
my_list[1] = 10
print(my_list)
10 Explain how you can create a copy of a list. K1 CO4
11 What is the output of the following code snippet? K1 CO4
my_tuple = (1, 2, 3)
print(my_tuple[0])
12 How would you add a key-value pair to a dictionary? K1 CO4
13 What is the result of the following dictionary operation? K1 CO4
my_dict = {'a': 1, 'b': 2}
my_dict.update({'c': 3})
print(my_dict)
14 How do you access the value associated with a specific key in a dictionary? K1 CO4
15 What does the del keyword do in the context of dictionaries? K1 CO4
16 What will be the output of this code snippet? K1 CO4
my_list = [1, 2, 3]
new_list = my_list[:]
print(new_list)
17 How do you iterate over a list using a for loop? K1 CO4
18 What is the purpose of the copy() method for lists? K1 CO4
19 What does the list.remove() method do? K1 CO4
20 How do you convert a list to a tuple? K1 CO4
21 How do you access the value associated with a specific key in a dictionary? K1 CO4
22 How can you check if a key exists in a dictionary? K1 CO4
23 What does the dict.get() method do? K1 CO4
24 How do you remove a key-value pair from a dictionary? K1 CO4
25 What is the output of this list comprehension? K1 CO4
S.No Question K CO
Level
1 Write a Python function to sort a list of numbers in ascending order using the bubble sort K2 CO4
algorithm. Explain how it works.
2 Create a program to generate a histogram from a list of numbers and explain how the K2 CO4
histogram is represented.
3 Develop a Python program to input student marks, calculate the average, and print a K2 CO4
statement about each student's performance based on the average.
4 Implement a function to clone a list and explain the difference between shallow and K2 CO4
deep copies.
5 Write a Python function that returns multiple values as a tuple and demonstrates tuple K2 CO4
assignment.
6 Create a program to prepare a retail bill that includes item names, quantities, prices, and K2 CO4
calculates the total amount and discount.
7 Use list comprehension to generate a list of squares for numbers from 1 to 10. Explain K2 CO4
how list comprehensions work.
8 Write a Python function that counts the occurrences of each element in a list and returns K2 CO4
a dictionary with the counts.
9 Implement a program to merge two lists and remove duplicates, and explain the K2 CO4
merging process.
10 Create a function that processes a list of tuples (name, score) and calculates the average K2 CO4
score.
11 Write a Python script to sort a list of tuples based on the second element in each tuple. K2 CO4
12 Implement a function to generate a frequency histogram from a list of strings, where the K2 CO4
histogram shows the frequency of each character.
13 Write a Python function to filter and return even numbers from a list using list K2 CO4
comprehension.
14 Create a program to convert a list of dictionaries into a dictionary of lists where each key K2 CO4
in the dictionary corresponds to a list of values from the dictionaries.
15 Write a function to remove all occurrences of a specific element from a list and return K2 CO4
the modified list.
16 Implement a Python function to calculate and display the maximum and minimum K2 CO4
values from a list of integers.
17 Create a function to return a dictionary where the keys are unique elements from a list K2 CO4
and the values are the count of those elements.
18 Write a Python script to reverse a list using slicing and explain how slicing works. K2 CO4
19 Develop a program to sort a list of strings in alphabetical order and demonstrate how K2 CO4
string sorting is performed.
20 Create a function that takes a tuple of integers and returns a new tuple with the elements K2 CO4
in reverse order.
Files and exceptions: text files, reading and writing files, format operator; command line arguments, errors
and exceptions, handling exceptions, modules, packages; Illustrative programs: word count, copy file,
Voter’s age validation, Marks range validation (0-100).
PART-A (2 Marks)
S.No Question K CO
Level
1 K1 CO5
How do you open a text file for reading in Python?
2 K1 CO5
What is the method to write a string to a text file in Python?
3 K1 CO5
How can you read the entire content of a file into a single string?
4 K1 CO5
What is the purpose of the format() method in Python?
5 K1 CO5
How can you handle an IOError exception when opening a file?
6 K1 CO5
What does the file.seek(0) method do?
7 K1 CO5
How do you close a file after opening it?
8 K1 CO5
What does the try-except block do in exception handling?
9 K1 CO5
What is the purpose of the finally block in exception handling?
10 K1 CO5
How do you import a specific function from a module?
11 K1 CO5
What is the difference between import module and from module import function?
12 K1 CO5
How do you check if a file exists before attempting to open it?
13 What is the function of the os.path.join() method? K1 CO5
14 K1 CO5
How can you create a new file and write content to it?
15 K1 CO5
What does the os.path.exists() function do?
16 K1 CO5
How do you handle an exception if the file is not accessible due to permissions?
17 K1 CO5
How do you open a file in append mode?
18 K1 CO5
What is the purpose of the with statement when working with files?
19 K1 CO5
What does the file.read() method do?
20 K1 CO5
How can you count the number of lines in a file?
21 K1 CO5
How do you check if a key exists in a dictionary?
22 K1 CO5
What does the dict.get() method do?
23 K1 CO5
How do you import all functions from a module?
24 K1 CO5
What is the purpose of the import statement in Python?
25 K1 CO5
How do you use the sys.argv to handle command line arguments?
S.No Question K CO
Level
1 Write a Python program to count the number of words in a text file and explain your K2 CO5
approach.
2 Develop a Python script to copy the contents of one file to another, including handling K2 CO5
errors and ensuring that the destination file is created properly.
3 Create a function to validate a voter's age from user input and handle invalid age entries. K2 CO5
Explain how you would manage edge cases.
4 Write a Python program that reads a text file, processes its content, and writes the K2 CO5
processed data to a new file, with proper error handling.
5 Implement a function to validate that student marks are between 0 and 100. The function K2 CO5
should handle invalid inputs and return appropriate messages.
6 Create a module with functions for reading, writing, and appending to text files. K2 CO5
Demonstrate how to import and use this module in another script.
7 Write a Python script that takes command line arguments for file names and operations K2 CO5
(e.g., word count, line count) and performs the specified operations.
8 Design a program that handles multiple file operations, such as opening, reading, K2 CO5
writing, and closing files, with appropriate exception handling.
9 Develop a function to handle exceptions that may occur during file operations, such as K2 CO5
file not found, permission denied, and I/O errors.
10 Create a Python script that uses the argparse module to handle command line arguments K2 CO5
for specifying input and output files and demonstrates various file operations.
11 Implement a function that reads a CSV file and calculates statistics such as the average K2 CO5
and total of a specified numeric column.
12 Write a Python program that reads user input from the command line, writes it to a file, K2 CO5
and handles potential file errors gracefully.
13 Create a function that splits a text file into multiple smaller files based on a specified K2 CO5
number of lines and explain the implementation.
14 Design a Python module that includes functions for error handling during file operations K2 CO5
and demonstrates how to use these functions in a script.
15 Write a script to validate a range of numbers read from a file, ensuring they fall within a K2 CO5
specified range, and handle any errors during processing.
16 Develop a Python program to create and manage a simple log file that records various K2 CO5
events or errors during execution.
17 Create a Python script that reads a file containing multiple lines of text and processes K2 CO5
each line to count occurrences of specific keywords.
18 Write a Python function to validate and correct malformed data in a file, and ensure the K2 CO5
file content adheres to specified formats.
19 Implement a Python script that demonstrates how to use the shutil module for file K2 CO5
copying and moving, with proper exception handling.
20 Design a comprehensive file processing script that reads a text file, performs operations K2 CO5
such as sorting and filtering, and writes the results to a new file.
S.No Question K CO
Level
1 Create a comprehensive file processing system that reads, processes, and writes data to K3 CO5
multiple files. Include features such as error handling, file management, and user
interaction.
2 Develop a robust Python package for file operations that includes modules for reading, K3 CO5
writing, copying, and deleting files. Demonstrate how to use this package in various
scenarios.
3 Write a Python program that uses command line arguments to specify input and output K3 CO5
files, performs multiple file operations (e.g., word count, line count), and includes
detailed exception handling.
4 Design a file validation system that reads data from a file, validates it according to K3 CO5
specific rules (e.g., age validation, marks range), and generates a report of validation
results.
5 Create a detailed Python script that performs advanced file operations, such as merging K3 CO5
multiple files into one, while handling errors and ensuring data integrity.
6 Develop a Python module that includes functions for complex file management tasks, K3 CO5
such as file comparison, merging, and splitting, and demonstrate how to use this module
in a script.
7 Write a Python program that reads data from a CSV file, processes it to compute statistics K3 CO5
(e.g., averages, totals), and handles various exceptions that may occur during file
operations.
8 Implement a comprehensive error-handling system in a Python script that performs K3 CO5
various file operations, including reading, writing, and appending, with robust exception
management.
9 Design a Python application that uses a package for file operations and demonstrates K3 CO5
advanced techniques such as file encryption, compression, and secure handling.
10 Create a Python program that uses the argparse module to handle complex command line K3 CO5
arguments for various file operations and includes detailed exception handling and
validation.