python QB (1)
python QB (1)
PART-A
UNIT-I
1. Define Algorithm
An algorithm is a finite set of well-defined steps or rules to solve a specific
problem. It outlines a clear process for arriving at a solution. Algorithms are essential
in computer science and mathematics .
PART B&C
1. State the Towers of Hanoi problem. Outline a solution to the Towers of Hanoi
problem with relevant diagrams.(JAN 2022)
2. i)Discuss about the building blocks of algorithms. (DEC/JAN 2019)
3. ii)Identify the simple strategies for developing an algorithm.(DEC/JAN 2019)
4. i)Draw a flow chart to accept three distinct numbers, find the greatest and print the
result. (JAN 2022)
5. ii)Draw a flow chart to find the sum of the series (JAN 2022)
a. 1+2+3+4+5+……+100.
6. 4. What is recursion ? Write and explain a python program to find a factorial of
number using recursion.(APRIL/MAY 2022)
7. 5. i)What is an algorithm? Summarize the characteristics of a good algorithm.
(APRIL/MAY 2019)
8. ii)Outline the algorithm for displaying the first n odd numbers. (APRIL/MAY 2019)
9. 6.Explain in detail about the Notation of Algorithm.(NOV/DEC 2022)
Unit-II
3. Compare interpreter and compiler. What type of translator is used for python?
An interpreter translates and executes code line-by-line, while a compiler
translates the entire code at once. Python uses an interpreter.
5. What is a variables?
A variable is a named memory location that stores a value, which can be
changed during program execution.
7. Outline the logic to swap the content of two identifiers without using third
variable
Use arithmetic to swap without a third variable:
a = a + b, b = a - b, a = a - b.
10. What is a tuple? How literals of type tuple are written? Give example.
A tuple is an immutable ordered collection defined with parentheses, like
my_tuple = (1, 2, 3).
PART B&C
1. Explain in detail about precedence of python operators and the associativity of python
operators. (NOV/DEC 2022)
2. Write and explain the python program to swap two numbers with and without temporary
variables. (APRIL/MAY 2022)
3. What is the role of an interpreter? Give a detailed note on python interpreter and
interactive mode of operation. Explain how python works in interactive mode and script
mode with examples. (NOV/DEC 2022)
4. What are statements and expressions? How are they constructed from variable and
expressions in Python? (APRIL/MAY 2019)
5. Explain about various datatypes used in python with examples. (NOV/DEC 2021)
6. Name the types of operators supported by python and outline any two with an example.
(NOV/DEC 2022)
UNIT-III
1. Name the two types of interative statements supported by python
Python supports for loops and while loops for iteration. for loops iterate over a
sequence, while while loops continue until a condition is false.
7. Define function and list any two advantages of using the function.
A function is a reusable block of code that performs a specific task.
Advantages include code reusability and improved readability, as well as easier
debugging.
20. Explain the difference between deep copy and shallow copy.
A shallow copy creates a new object but inserts references to the original
object's elements, while a deep copy creates a new object and recursively copies all
elements, resulting in independent copies.
PART B & C
1. Write a python program to find the square root of a number without using inbuilt function
and explain the same. (NOV/DEC 2022)
2. Write a python program for linear search and binary search and explain its implementation
in detail. (NOV/DEC 2022)
3. List the three types of conditional statements and explain them. (DEC/JAN 2019)
4. i) Python strings are immutable. Justify with an example. (DEC/JAN 2019)
ii) What is difference between break and continue in python? Explain with suitable
examples. (APRIL/MAY 2022)
5. Outline about function definition and function call with an example. (APRIL/MAY 2019)
6. What is string function in python? Explain any three python string methods with an
example. (APRIL/MAY 2022)
UNIT-IV
1. What is a list? How lists differ from tuples?
A list is a mutable, ordered collection of items defined with square brackets,
e.g., my_list = [1, 2, 3]. Unlike tuples, lists can be modified (items can be added or
removed), while tuples are immutable.
9. Give a function that can take a value and return the first key mapping to that
value in a dictionary.
def get_key_by_value(d, value):
for k, v in d.items():
if v == value:
return k
return None
10. Let list=[‘a’,’b’,’c’,’d’,’e’,’f’]. find the following.
(a)list [1:3] (b) t[:4] (c) t[3:]
(a) list[1:3] returns ['b', 'c'].
(b) t[:4] returns ['a', 'b', 'c', 'd'] (assuming t is defined as list).
(c) t[3:] returns ['d', 'e', 'f'].
PART B &C
1. Demonstrate with the code various operation that can be performed on Tuples.
(APRIL/MAY2018)
2. Define python lists. How to add the elements in the list. Explain with suitable example
programs. (APRIL/MAY2022)
3. Write a python program to create a Dictionary and sort the content based on values in
reverse order. (JANUARY2022)
4.i) Discuss the different options to traverse a list.
ii) Demonstrate the working of + and *and slice operators in
Python. (DEC/JAN2019)
5. Outline the algorithm and write a python program to sort the number in ascending order
using Merge sort.(APRIL/MAY 2018).
6.Write a python script to sort N numbers using insertion sort. (NOV/DEC 2021)
UNIT-V
2. What is command line arguments? How to use the command line arguments
in python?
Command line arguments are inputs passed to a script when executed
from the command line. In Python, they can be accessed using the sys.argv list
from the sys module.
7. How will you update the content of ome file to another file in python?
Open both files and read content from the source file, then write it to the
destination file:
with open('source.txt', 'r') as src, open('dest.txt', 'w') as dest:
dest.write(src.read())
8. Write methods to rename and delete files.
To rename a file, use os.rename('old_name.txt', 'new_name.txt'). To delete a
file, use os.remove('filename.txt') from the os module.
PART B&C
1. Why does the python require file handling. Explain opening files in python with all modes.
(APRIL/MAY 2022)
2. Describe how exceptions are handled in python with necessary examples. (DEC/JAN 2019)
3. i) Design a python code to count the number of words in a file. (APRIL/MAY 2018)
ii) How to merge multiple files in to a new file using python. (NOV/DEC 2019)
4. i) Discuss about format operators in file processing. (DEC/JAN 2019)
ii)Write a python program to dump objects to a file using pickle. (NOV/DEC 2022)
5. Write a program to concatenate the content of two files into a single file. Get the input for
two files from the user and concatenate it. (JANUARY 2022)
6. What are modules in python.? How will you import them.? Explain the concept by
creating and importing modules in python. (NOV/DEC2019)