Week 3
Week 3
2. Data Structure is a way by which you can organize/arrange your data. Which of the
following statements are true about List Data Structure: [MSQ]
a. It is a flexible Data Structure
b. Elements could be added to a list.
c. Elements could be subtracted from a list.
d. This_is_not_List = [ ] is an empty list
Answer: All the options are correct.
List is a flexible data structure. Python lists allow us to add or delete elements form a
list. It is mutable. We can use list.append(element) to add elements to a list. We can
use list.pop(index) to remove element from the list.
Answer: Option d
L[2] = “Anthony”
L[1] = “Akbar”
L[0] = “Amar”
a. "1111111111"
b. "0000000000"
c. A string with some 1s and some 0s
d. The function will raise an error
Answer: Option c
result = sum(numbers)
average = result/n
a. "Python"
b. A random permutation of the letters in "python"
c. "random"
d. The function will raise an error
Answer: option b
Programming Problems
11. You are given a list marks that has the marks scored by a class of students in a
Mathematics test. Find the median marks and store it in a float variable
named median. You can assume that marks is a list of float values.
(1) Sort the marks in ascending order. Do not try to use built-in methods.
(2) If the number of students is odd, then the median is the middle value in the sorted
sequence. If the number of students is even, then the median is the arithmetic mean of the two
12. Write a python program to generate a password with the following specifications:
b. It must contain at least 2 upper case letters, 1 digit, and 1 special symbol.
13. Write a Python program that takes a string as input from the user. It does following
14. Write a program that generates a list containing random integers between 0 and 100.
the sort function used in problem 11. You are not allowed to use any Python