Module 2: Problem Solving Techniques Unit 1
Module 2: Problem Solving Techniques Unit 1
Module 2: Problem Solving Techniques Unit 1
Lecture 2:
A Very Simple Program: Entering and Printing Your Name The goal of this programming exercise is
simply to get you more comfortable with using IDLE, and to begin using simple elements of Python.
Standard elements of a program include the ability to print out results (using the print operation), the
ability to read input from a user at the console (for example using the raw input or input function),
and the ability to store values in a variable, so that the program can access that value as needed.
Problem 1
Learn Python for Beginners:
https://www.python.org/about/gettingstarted/
or
https://pynative.com/
Prints out the user’s last name and date of birth, in that order.
An example of an interaction with your program is shown below (the words printed in blue are from
the computer, based on your commands, the words in black are a user’s input – the colors are simply
here to help you distinguish the two components):
Hints: https://python.swaroopch.com/basics.html
pg. 1
CDS/CDS101/IISERBPR
Hand-In Procedure
1. Save your code in PS1.py Do not ignore this step or save your file(s) with different names.
Lecture 3:
Q.1) What does it mean for a program to terminate?
Q.2) What is a for loop?
Problem 1:
Python Program to Check If A Number Is A Perfect Square? Run the program for some test cases
gave the following output,
Hint: Square root of the number is calculated with math.sqrt method and the result is stored in root
variable
https://djangocentral.com/python-program-to-check-if-a-number-is-perfect-square/
Hand-In Procedure
1. Save your code in PS2.py Do not ignore this step or save your file(s) with different names.
2.Submit
Lecture 4:
Q.1) What is decomposition?
Q.2) What is abstraction?
Given two integer numbers return their product only if the product is equal to or lower than 100,
else return their sum.
pg. 2
CDS/CDS101/IISERBPR
Show Hint
Hand-In Procedure
1. Save your code in PS3.py Do not ignore this step or save your file(s) with different names.
2.Submit
Problem 4:
Print the sum of the current number and the previous number. Write a program to iterate the
first 10 numbers and in each iteration, print the sum of the current and previous number.
Expected Output:
Show Hint
pg. 3
CDS/CDS101/IISERBPR
Next, display the current number (i), previous number, and the addition of both numbers in
each iteration of the loop. At last, change the value previous number to current number
(previous_num = i).
Problem 5:
Print characters from a string that are present at an even index number
Write a program to accept a string from the user and display characters that are present at an even
index number.
For example, str = "HelloDear" so you should display ‘H’, ‘l’, ‘o’, ‘e’, ’r’.
Expected Output:
Problem 6:
Write a program to remove characters from a string starting from zero up to n and return a new
string.
For example: remove_chars("HelloDear", 4) so output must be oDear. Here we need to remove first
four characters from a string.
Expected Output:
Hint: Use string slicing to get the substring. For example, to remove the first four characters and the
remeaning use s[4:].
pg. 4
CDS/CDS101/IISERBPR
Problem 7:
Write a function to return True if the first and last number of a given list is same. If numbers are
different then return False.
Expected Output:
Problem 8:
Iterate the given list of numbers and print only those numbers which are divisible by 6
Expected Output:
Problem 9:
Write a program to find how many times substring “Science” appears in the given string.
Given:
Hint:
Expected Output:
Problem 10:
pg. 5
CDS/CDS101/IISERBPR
22
333
4444
55555
Lecture 5:
Q.1) What is mutability?
Q.2) What is the important difference between a list and a tuple?
Q.3) What is cloning?
Lecture 6:
Q.1) What is recursion?
Lecture 7:
Q.1) Why do computers use binary representations?
Q.3) When debugging, how can you ensure that the values in your program are the ones you think
they are?
Lecture 8:
Q.1) Why is efficiency important?
pg. 6
CDS/CDS101/IISERBPR
Lecture 9:
Q.1) What is indirection (in computing)?
Q.2) We know that a linear search works on all lists and is O(len(L)). Can we sort a list in sub-
linear time?
Unit 1 Completed
pg. 7