SACP Assignment 2
SACP Assignment 2
1. Make a list of the first eight letters of the alphabet, then using the slice operation do the
following operations:
a. Print the first three letters of the alphabet.
b. Print any three letters from the middle.
c. Print the letters from any particular index to the end of the list
2. Write a program to sort the elements in ascending order using selection sort.
3. Write a program to sort the elements in ascending order using insertion sort.
4. Write a Python program to use binary search to find the key element in the list.
5. Write a program that reads the date in the format (dd/mm/yyyy) and replaces the ‘/’ with
a ‘-’ and displays the date in (dd-mm-yyyy) format.
6. Write a program that parses a binary number to a decimal integer. For example, 11001
(1 * 24 + 1 * 23 + 0 * 22 + 0 * 21 + 1 * 20 ).
7. Consider the following four string variables, as shown:
city1 = "London"
city2 = "Paris"
city3 = "London"
city4 = "Sydney"
What are the results of the following expressions?
a. city1 == city2
b. city3.count('n')
c. city1 <= city4
d. city2.upper()
e. len(city4)
f. city1.lower()
8. Write a function to insert a string in the middle of the string.
9. Write short notes on the following methods. a. keys() b. values() c. get(key) d. clear()
10. Explain nested dictionaries with an example.
11. Define frozen set with examples