Problem Solving and Python Programming
Problem Solving and Python Programming
I SEMESTER
(Regulation – 2019)
Prepared by
1
Unit 1
ALGORITHMIC PROBLEM SOLVING, DATA TYPES
Algorithms, building blocks of algorithms (statements, control flow, functions), notation
(pseudo code, flow chart), Python interpreter and interactive mode, values and types:
int,float,boolean, string, and list; Variables, Operators and expressions, statements, tuple
assignment, precedence of operators, comments, Illustrative programs: Algorithm for arithmetic
expression (addition and subtraction)
Part A
Q. No. Questions Competence BT Level
1. List the various control flow structures Remember BTL 1
2. Define algorithm. Understand BTL 2
3. Distinguish between pseudocode and flowchart. Analyze BTL 4
4. Write the building blocks of algorithms. Remember BTL 1
5. Discuss different modes of operation in python. Understand BTL 2
Write a simple python program to perform addition of two
6. Apply BTL3
values.
7. Distinguish between string and list data types. Analyze BTL 4
8. Infer how does python interpreter work? Evaluate BTL 5
9. Write an algorithm for basic arithmetic operations. Create BTL 6
10. Evaluate the order of precedence of operators in python. Evaluate BTL 5
11. State Tuple Assignment. Remember BTL 1
Develop an algorithm to convert Temperature in Celsius
12. Create BTL 6
to Fahrenheit.
13. Define Variable. Remember BTL 1
14. Show how Comment is used in python. Remember BTL1
15. Examine a simple pseudo code to print n integers. Apply BTL 3
16. What is data type in python? List the various data types. Understand BTL 2
17. Draw the flowchart for calculating simple interest. Evaluate BTL 5
18. Write the Pseudo code for greatest among two numbers. Apply BTL3
19. Mention the features of Python. Analyze BTL 4
20. Discuss the problem solving techniques. Understand BTL 2
21. Classify expressions by applying different operators. Apply BTL 3
List the basic symbols used in drawing the flowchart for
22. Remember BTL 1
sequence control structure.
23. Classify different types of statements in python. Analyze BTL 4
24. List the types of operators available in python. Understand BTL 2
Part B
Analyze the model of interpreter and explain how python
1. Analyze BTL 4
works in different modes. (13)
Evaluate the different values (data types) and types of
2. Evaluate BTL 5
values that can be used in Python. (13)
(i)Summarize the advantages and disadvantages of
3. flowchart.(6) Understand BTL 2
(ii) Summarize the symbols used in flowchart.(7)
List the different operators in python and estimate the
4. Remember BTL 1
precedence of execution. (13)
Explain pseudocode and its rules also give examples for
5. Remember BTL 1
sequence , selection and repetition type problems.(13)
2
List the types of operators in python and thus explain the
6. Apply BTL 3
different expressions involved in python. (13)
With neat sketch explain the following building blocks of
algorithm:
7. Remember BTL 1
(i) Statements(5)
(ii) Control flow(8)
Analyze the need for functions and explain with an
8. Analyze BTL 4
example. (13)
(i) Develop a flowchart to check whether the given
number is a prime number or not.(7)
9. Apply BTL 3
(ii) Develop a pseudocode to perform arithmetic
operations. (6)
(i)What is an algorithm? List the characteristics of a good
10. algorithm.(6) Remember BTL 1
(ii)Write an algorithm find the square root of a number.(7)
Design the flowchart and write that calculates salary of an
employee. Prompt the user to enter the Basic salary, HRA,
11. TA and DA. Add these components to calculate the Gross Create BTL 6
salary. Also, deduce 10% salary from the Gross salary to
be paid as tax. (13)
Write an algorithm and Pseudo code for the following:
12. (i). Calculating area and circumference of a circle. (7) Understand BTL 2
(ii). Check given year is leap year or not. (6)
Explain the sequence data types in python with examples.
13. Evaluate BTL 5
(13)
Discuss the various modes of Python Interpreter and
14. Apply BTL 3
explain with example. (13)
Summarize the difference between algorithm, flowchart
15. Understand BTL 2
and pseudocode.(13)
Explain the following.
(i) Tuple assignment(4)
16. Understand BTL 2
(ii) Comments(4)
(iii) Statements in python(5)
Using a simple python snippet, analyze different values,
17. Analyze BTL 4
types and expression and explain them. (13)
Part C
Write an algorithm, pseudocode and draw the flowchart to
1. Create BTL 6
find the factorial of a number n.(15)
Design a calculator with python code by defining its
2. Create BTL 6
algorithm using different notations. (15)
Write a program to explain the various operators involved
3. in python and how an expression evaluated using Create BTL 6
precedence of operators.
Write an algorithm, pseudocode and draw the flowchart to
4. Evaluate BTL 5
check whether the given number is palindrome or not.(15)
Rate the order of execution of different expressions by
5. Evaluate BTL 5
evaluating them through python program. (15)
3
Unit 2
CONTROL FLOW STATEMENTS AND FUNCTIONS
Conditionals: Boolean values and operators, conditional (if), alternative (if-else), chained
conditional (if-elif-else); Iteration: state, while, for, break, continue, pass; functions, function
definition and use. Fruitful functions: return values, parameters, local and global scope,
recursion. Illustrative programs: exchange the values of two variables, square root, printing n
numbers iteratively.
Part A
Q. No. Questions Competence BT
Level
1. Define function and state its use. Remember BTL 1
2. What does recursive function implies? Remember BTL 1
3. Analyze the different kinds of arguments. Analyze BTL 4
4. Evaluate the importance of fruitful functions. Evaluate BTL 5
5. Analyze the need to divide a program into functions. Analyze BTL 4
Write a program to print n numbers iteratively using
6. Create BTL 6
function.
Using the concept of functions, calculate the area of a
7. Apply BTL 3
circle.
Using the concept of tuple assignment, how will you
8. Apply BTL 3
swap two values?
9. What do you mean by fruitful function? Understand BTL 2
10. Outline the scope of variables. Understand BTL 2
11. Write the syntax of if-else statements. Remember BTL 1
12. Differentiate for loop and while loop. Analyze BTL 4
13. List any three built-in functions and its usage. Understand BTL 2
14. Write a function without argument and with return type. Analyze BTL 4
15. Differentiate local and global variables. Apply BTL 3
16. Write a program to find the sum of the digits of a number Evaluate BTL 5
17. Illustrate the flowchart of if-elif-else statements. Apply BTL 3
How would you test the significance of for loop with else
18. Evaluate BTL 5
in an example.
19. Present the flow of execution for a while statement. Remember BTL 1
20. Write the syntax for function definition. Remember BTL 1
21. Name the type of Boolean operators. Remember BTL 1
22. Describe break statement with an example. Understand BTL 2
23. Write a program to find square root of a given number. Create BTL 6
24. Give the syntax for pass and continue statements. Understand BTL 2
Part B
Using the concept of control structure determine the
1. Apply BTL 3
prime numbers in given range using Python.(13)
Write a program to determine the factorial of a given
2. Evaluate BTL 5
number with and without the use of recursion.(13)
What does fruitful function refers to? How it can be
3. Understand BTL 2
used? Explain with an example.(13)
Write the syntax and explain the concept of
4. (i) Recursive function with an example. (7) Remember BTL 1
(ii) to search an element using linear search (6)
4
List the different types of arguments / parameters used in
5. Remember BTL 1
function with suitable examples.(13)
Using a python program, analyze the different logic
6. Analyze BTL 4
behind swapping the values between variables.(13)
Write a program to find the square root of a number by
7. Create BTL 6
Iterative newton’s method. (13)
Explain the looping statements (while and for loops) with
8. Understand BTL 2
an example. (13)
List the different types of conditional control statements
9. Understand BTL 2
and explain them with suitable example.(13)
Describe the concept of binary search with suitable
10. Evaluate BTL 5
example and write python code to implement.
(i) Write a Python program to find the GCD of given two
numbers. (6)
11. Apply BTL 3
(ii)Write a Python program to find the exponent of a
number using recursion. (7)
(i). Write a python program to find the greatest among
three numbers. (6)
12. Understand BTL 2
(ii). Write a program to check the given number is
Armstrong number or not. (7)
Explain with an example break and continue statements
13. Analyze BTL 4
using while loop.(13)
Write a python code to print all numbers in a range
14. Apply BTL 3
(a,b)divisible by a given number (n).(13)
What is function? How a function is defined and called
15. Remember BTL 1
in python? Explain with a simple program.(13)
(i) Write a Python program to find the sum of N natural
numbers.(9)
16. Remember BTL 1
(ii)What is the use of pass statement? Illustrate with an
example.(4)
17. (i). Write a Python program using function to find the
sum of first ‘n’ even numbers and print the result. (7)
Analyze BTL 4
(ii). Write a python program to find the roots of the
quadratic equation. (6)
Part C
Create a user defined fruitful function to test a given year
1. Create BTL 6
is a leap year.(15)
Write a function to determine whether a given natural
2. number is a perfect number. A natural number is said to Create BTL 6
be a perfect number if it is the sum of its divisors.(15)
(i). Write a python program to implement student mark
system using chained conditional if control structure. (8)
3. (ii). Write a python program to find the given number is Evaluate BTL 5
positive, negative or zero using Nested if conditional
control structure. (7)
Write a function reads two numbers and evaluates
whether they or co-prime or not. Two numbers are said
4. Evaluate BTL 5
to be co-prime if they do not have any common divisor
other than one.(15)
5
Write a function to multiply two non-negative numbers
5. by repeated addition and evaluate the result by normal Evaluate BTL 5
procedure.(15)
Unit 3
LIST AND TUPLES
Lists: list operations, list slices, list methods, list loop, mutability, list parameters; Tuples: tuple
assignment, tuple as return value; comparison of lists and tuples. Illustrative programs:
Selection sort, insertion sort, Quick sort.
Part A
Q. No. Questions Competence BT
Level
1. Define Python list. Remember BTL 1
2. Mention the list operations. Remember BTL 1
3. What are the different ways to create a list? Remember BTL 1
4. Illustrate negative indexing in list with an example. Apply BTL 3
5. How to slice a list in Python? Understand BTL 2
6. Point out the methods that are available with list object. Analyze BTL 4
7. Show the membership operators used in list. Apply BTL 3
8. Define Python Tuple. Remember BTL 1
9. Write a program to add two lists. Create BTL 6
10. Classify the Python accessing elements in a Tuples. Apply BTL 3
11. Point out the methods used in Tuples Analyze BTL 4
12. How tuple as arguments to a function? Give example. Evaluate BTL 5
13. Write the syntax and purpose of insert( ) method in list. Understand BTL 2
14. How for loop used in sequence objects? Give example. Apply BTL 3
15. Point out the advantages of tuple. Analyze BTL 4
16. Evaluate the difference between lists and tuples. Evaluate BTL 5
17. Show how Tuples are used as return values? Evaluate BTL 5
18. What does sorting refers to? Remember BTL 1
19. What does the term mutability refers to? Understand BTL 2
Write a program to create a list of even numbers in a
20. Create BTL 6
given range.
21. Write the syntax for concatenating two lists in python. Understand BTL 2
22. Show how Tuples are immutable? Understand BTL 2
23. List the different sorting algorithms. Remember BTL 1
With the help of a program, list the different methods in
24. Analyze BTL 4
list.
Part B
Discover an algorithm and write a python program to sort
1. Analyze BTL 4
the numbers in ascending order using insertion sort. (13)
Describe the following
(i) Creating the list (4)
2. (ii) Accessing values in the lists (3) Remember BTL 1
(iii) Updating the list (3)
(iv) Deleting the list elements (3)
(i) Analyze the basic list operations in detail with
3. necessary programs. (7) Analyze BTL 4
(ii) Write a Python program to add two matrices. (6)
6
(i) Mention the Python list methods with examples. (8)
(ii) Why it is necessary to have both the functions
append( ) and extend( )? What is the result of the
4. following expression that uses append( ) where it Remember BTL 1
probably intended to use extend( )?
>>>lst=[1,2,3]
>>>lst.append([4,5,6]) (5)
Demonstrate the working of +,* and slice operators in
5. Apply BTL 3
python lists and tuples. (13)
(i) What is a Python Tuple? What are the advantages of
6. Tuple over list? (5) Remember BTL 1
(ii)“Tuples are immutable”. Explain with example. (8)
Illustrate the ways of creating the Tuple and the Tuple
7. Apply BTL 3
assignment with suitable programs. (13)
(i)What are the accessing elements in a Tuple? Explain
with suitable programs. (7)
8. Remember BTL 1
(ii) Explain how to return more than one value from a
function with the help of a program. (6)
(i). Explain the basic Tuple operations with examples.(6)
(ii). Illustrate a program to check whether an element ‘y’
9. and ‘a’ belongs to the tuple mytuple = Understand BTL 2
(‘p’,’y’,’t’,’h’,’o’,n’) and after printing the result, delete
the Tuple. (7)
Write a program to perform the following matrix
operations.
10. Apply BTL 3
(i). Addition of two matrices
(ii). Transpose of a matrix.
How list is used in loops? Give an example each for
11. Understand BTL 2
while loop and for loop used in lists.
Given a tuple test_tup = (4, 5, 4, 5, 6, 6, 5). Write a
12. program to find the frequency of each element. [ Output Evaluate BTL 5
like as {4: 2, 5: 3, 6: 2} ]
Describe the built in functions with Tuples and write a
13. program to use Max(), Min() and sorted() methods in Understand BTL 2
Tuple.(13)
(i). Discuss a)Tuples as return values b) Variable Length
Argument Tuples (6)
14. Understand BTL 2
(ii) Write a program to illustrate the comparison
operators in Tuple. (7)
Write a Python program to store ‘n’ numbers in a list and
15. Evaluate BTL 5
sort the list using selection sort. (13)
Using the functions and methods, analyze the differences
16. and similarities of lists and tuples with examples for Analyze BTL 4
each. (13)
Write a program to perform the logic of quick sort
17. Create BTL 6
algorithm. (13)
Part C
1. Write a function that takes a list of numbers as input
Create BTL 6
from the user and produces the corresponding cumulative
7
list. (15)
2. Write a function to perform sorting of given numbers and
Create BTL 6
present a list of odd and even numbers separately. (15)
3. Write a python program to add tuple to list and vice –
Create BTL 6
versa. (15)
4. Write a function ‘leftCirculate’ that takes a list as an
input and left circulates the values in the list so that in the
final list, each value is left shifted by one position and Evaluate BTL 5
leftmost value in the original list now appears as the
rightmost value.(15)
5. Write a program to delete all the duplicate elements in a
Evaluate BTL 5
list.(15)
Unit 4
STRINGS, DICTIONARIES & SET
Strings: string slices, immutability, string functions and methods, string module; Dictionaries:
operations (create, access, add, remove) and methods (insert, delete). Set operation (Access,
Add, Remove). Comparison of dictionary and set
Part A
Q. No. Questions Competence BT Level
1. Define dictionary. Remember BTL 1
2. Examine different set functions. Analyze BTL 4
Write a program to perform union, intersection and
3. Create BTL 6
difference operation using set
Using the built in function update, how key value pair
4. Apply BTL 3
can be inserted?
5. What does key value pair refers to? Remember BTL 1
6. What is set? Remember BTL 1
7. List the dictionary operations. Remember BTL 1
8. List the mutable data types and immutable data types Remember BTL 1
9. How to create and delete a dictionary? Understand BTL 2
10. Write a python program to manipulate strings. Create BTL 6
What will be the output of print(str[2:5]) if str=’hello
11. Evaluate BTL 5
world!’?
12. How to add and remove data in set? Understand BTL 2
13. Describe any 4 methods used on a string. Apply BTL 3
14. What does D.item( ) returns? Give an example. Apply BTL 3
15. Do set supports indexing. Justify the answer. Analyze BTL 4
16. Are dictionary and set different. Justify your answer. Evaluate BTL 5
17. Write an example for string traversal. Understand BTL 2
18. Describe string module. Understand BTL 2
Write the usage of capitalize( ) and title( ) methods in
19. Apply BTL 3
string.
How does make a copy of dictionary using copy( )
20. Analyze BTL 4
method?
21. How can you insert values into a dictionary? Evaluate BTL 5
22. What is the use of fromkeys( ) in dictionary? Understand BTL 2
23. What does the module mean? Remember BTL 1
24. What does the function join( ) in a string used for? Analyze BTL 4
8
Part B
1. (i) Define methods in a string with an example program
using at least 5 methods.(10) Remember BTL 1
(ii) How to access characters of a string?(3)
2. Write a program to count the number of common
Apply BTL 3
characters in a pair of strings.(13)
3. Describe the methods and operations of Dictionaries.(13) Remember BTL 1
4. Write a Python program to count the number of vowels
Understand BTL 2
in a string provided by the user.(13)
5. Write a program that takes a sentence as input from the
user and computes the frequency of each letter. Use a Apply BTL 3
variable of dictionary type to maintain the count.(13)
6. Python strings are immutable. Justify with an example
Analyze BTL 4
program. (13)
7. (i) Analyze string slicing. Illustrate how it is done in
python with an example.(6)
(ii) Write a python code to search a string in the given Analyze BTL 4
list.
(7)
8. Using the concept of dictionary, Show a dictionary of
Remember BTL 1
frequency of words for a given text.(13)
9. Compare and contrast different functions and methods
Analyze BTL 4
used in dictionaries and set.(13)
10. Describe set and explain its operations with suitable
Understand BTL 2
examples.(13)
11. Describe different functions associated with sets.(13) Understand BTL 2
12. Write a function that takes a string as a parameter and
replaces the first letter of every word with the Evaluate BTL 5
corresponding uppercase letter.(13)
13. Write a Python program for adding elements to a
Evaluate BTL 5
dictionary.
14. What are the methods used to copy dictionaries? Write a
Apply BTL 3
program to copy the dictionary using those methods.
15. How to remove items from set? Explain the methods
Understand BTL 2
used for it with example.
16. Recollect the various dictionary operations and explain
Remember BTL 1
them with an example.(13)
17. Create a program to determine whether a string is a
Create BTL 6
palindrome or not.(13)
Part C
(i) Write a function to find the number of common
1. characters in two strings.(8) Create BTL 6
(ii) Write a program to reverse a string.(7)
Write a function that takes a number as an input
parameter and returns the corresponding text in words,
2. for example, on input 452, the function should return Create BTL 6
‘Four Five Two’. Use a dictionary for mapping digits to
their string representation.(15)
3. Using a dictionary variable, estimate the frequency of Evaluate BTL 5
9
each character in a sentence obtained from the user.(15)
(i). Write a Python program to check if two given sets
have no elements in common.
4. Create BTL 6
(ii). Write a Python program to remove the intersection
of a 2nd set from the 1st set.
Evaluate the different operations like union, intersection
5. Evaluate BTL 5
and differences of list using Set and functions.(15)
Unit 5
FILES, MODULES, PACKAGES
Files and exception: text files, reading and writing files, format operator; command line
arguments, errors and exceptions, handling exceptions, modules, packages; Illustrative
programs: word count, copy file.
Part A
Q. No. Questions Competence BT Level
1. Point out different modes of file opening. Analyze BTL 4
2. Define the access modes Remember BTL 1
3. Distinguish between files and modules. Understand BTL 2
4. Define read and write file Remember BTL 1
5. Describe renaming and deleting a file in python. Understand BTL 2
6. Discover the format operator available in files. Apply BTL 3
7. Examine the need for exceptions using an example Analyze BTL 4
8. Explain Built-in exceptions. Evaluate BTL 5
Difference between built-in exceptions and handling
9. Remember BTL 1
exception
Write a program to write a data in a file for both write
10. Evaluate BTL 5
and append modes.
11. How to import statements? Remember BTL 1
Find the error in the code given:
12. Create BTL 6
while True print (‘Hello world’)
13. Define package. Remember BTL 1
14. What are packages in Python? Remember BTL 1
Write the difference between read( ) and read(n)
15. Evaluate BTL 5
functions?
Accept five names from the user and write in a file
16. Analyze BTL 4
“name.txt”.
17. What is ‘value error’ in python? Apply BTL 3
18. What is base exception? Understand BTL 2
19. Examine buffering. Apply BTL 3
20. What do you mean by fileisatty() method Understand BTL 2
21. Discover except Clause with Multiple exception Apply BTL 3
Create a Python script to display the current date and
22. Create BTL 6
time.
23. Analyze the object as return values. Analyze BTL 4
24. Discuss a modular design Understand BTL 2
Part B
Write a Python program to demonstrate the file I/O
1. Analyze BTL 4
operations.(13)
10
Discuss the different modes for opening a file and
2. Understand BTL 2
closing a file.(13)
(i) Discover a program to catch a divide by zero
exception. Add a finally block too.(7)
3. Analyze BTL 4
(ii) Write a function to print the hash of any given file in
Python.(6)
(i) Describe the use of try block and except block in
python with syntax.(8)
4. Remember BTL 1
(ii) Describe with an example exceptions with arguments
in python.(5)
(i) Explain with example of writing a file(7)
5. Apply BTL 3
(ii) Discover syntax for reading from a file(6)
(i) Structure Renaming a file(7)
6. Analyze BTL 4
(ii) Explain about the files related methods(6)
(i) Describe python modules(6)
7. Remember BTL 1
(ii) Describe python packages(7)
Write a program that will prompt the user for a string and
8. a file name, and then print all lines in the file that contain Evaluate BTL 5
the string. Also interpret the obtained result.(13)
Identify the various methods used to delete the elements
9. Remember BTL 1
from the dictionary(13)
Describe in detail exception handling with sample
10. Remember BTL 1
program(13)
Illustrate a program to find the one’s complement of
11. Understand BTL 2
binary number using file.(13)
12. Write a program to display a pyramid. (13) Create BTL 6
Explain the terminology of raising an exception concept
13. Evaluate BTL 5
with sample program.
Write a program to count the total number of uppercase
14. Apply BTL 3
characters in a file in Python.
Explain the following:
15. (i). Predefined Modules Understand BTL 2
(ii). User defined Modules.
Write a program to find the number of instances of
16. Apply BTL 3
different digits in a given number. (13)
Explain with an example to copy the contents of one file
17. Understand BTL 2
to another.(13)
Part C
Create a program to compute price per unit weight of an
1. Create BTL 6
item using try – except – else block.(15)
Write a program that reads the contents of the file text.txt
and counts the number of alphabets, blank spaces,
2. lowercase letters and uppercase letters, the number of Create BTL 6
words starting with a vowel, and the number of
occurrences of the word ‘is’ in the file. (15)
Examine the following function percentage:
def percentage(marks,total):
3. Evaluate BTL 5
try:
percent=(marks/total)*100
11
except ValueError:
print('Value Error')
except TypeError:
print('TypeError')
except ZeroDivisionError:
print('ZeroDivisionError')
except:
print('any other error')
else:
print(percent)
finally:
print('Function percentage completed
12