Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

1. Trace the following program to search your name in the list.

def search(list):
list.sort()
while len(list)>1:
midpoint=len(list)//2
if searchname<list[midpoint]:
list=list[:midpoint]
else:
list=list[midpoint:]

if searchname==list[0]:
print(searchname,"is found in the List.")
else:
print(searchname,"is not found in the List.")

students_list = ["Susan","May Thadar Win","Min Khant","Min Pyae Sone Paing",


"Thuta Linn Latt May","Zue Nadi Lynn","Phoo Shwe Wut Hmone",
"La Wun May","Pwar Shwe Ou Maung","Thaw Bhone Nyi",
"Hein Swan Thit","Zwe Khant Htal"]
searchname = input("Enter the name you want to search: ")
search(students_list)

2. Write a Python Program as the following instructions.


a. Create the students_list that includes these students: Susan, May Thadar Win, Min
Khant, Min Pyae Sone Paing, Thuta Linn Latt May, Zue Nadi Lynn, Phoo Shwe
Wut Hmone, La Wun May, Pwar Shwe Ou Maung, Thaw Bhone Nyi, Hein Swan
Thit, Zwe Khant Htal.
b. Print how many students are there in the list.
c. Add “Kyal Sin”, “Lyun Htet Linn” and “Nano Cho” to the list.
d. Find the final index value of the list.
e. Print the helpful message to the user how to enter a valid index number.
f. Make sure the user input index number is valid.
g. Edit the student name: “Kyal Sin” to “Kyal Sin Lin Lint Aung” by asking the
index number for the name “Kyal Sin” in the list.
h. Remove “Kyal Sin Lin Lint Aung” from the list by asking the index number for
that.
i. Create and call the procedure to search your name in the list using Linear Search
Algorithm.

You might also like