Page 318 - Computer Science Class 11 Without Functions
P. 318
10. Consider the following statement:
myTup = (10, -4, 0, 3, -1, 6)
Which of the following statements will display the tuple, sorted in descending order?
a. tuple(sorted(myTup)
b. tuple(sorted(myTup, reverse=False))
c. tuple(sorted(myTup, desc))
d. tuple(sorted(myTup, reverse=True))
B. State whether the following statements are True or False:
1. We can replace an item in a list with another item. ________
2. pop() and remove() are similar functions, they take the element to be deleted from the list as arguments. ________
3. The element at a given position in a list can be changed using the assignment statement. ________
4. The function sort() can be used to arrange the elements of the tuple in ascending order. ________
5. The elements of the list can be repeated a specified number of times using the * operator. ________
C. Fill in the blanks.
1. A list comprises a comma-separated sequence of objects enclosed in ___________.
2. The function ___________ converts a string into a list.
3. The slice lst[:3] yields the list comprising of first ___________ elements of list lst.
4. The function ___________ returns a sorted list comprising the elements of the list passed as an argument, but without
modifying the original list.
5. ___________ is the concatenation operator.
D. Answer the following questions:
1. Write a program to find the largest element of a list without using the functions max(), min(), and sorted().
2. Write a program to find the largest element of a tuple without using the functions max(), min(), and sorted().
3. Write a program that accepts a date as an integer whose digits signify DDMMYYYY from left to right and displays a tuple of
numbers having the values (DD, MM, YYYY) in the following format:
Day : DD
Month: MM
Year : YYYY
4. Write a program that accepts an integer n as input and displays a tuple comprising the first n elements of the Fibonacci
sequence:
1, 1, 2, 3, 5, 8, 13, 21, 34, ….
5. What will be the output produced on the execution of the following code?
myList = [1, 0, -1]
newList = myList * 3
newList.insert(-1, 5)
indx = newList.index(5)
print(indx)
6. Write a program that accepts a list of numbers from a user and interchanges the elements at indices 0, 2, 4, … with those
at indices 1, 3, 5, … respectively. The program should display the resulted list. Assume that the number of elements in the
list is even.
7. Write a program that accepts a list of numbers from a user and interchanges the elements at indices 0, 2, 4, … with those at
indices 1, 3, 5, … respectively. The progam should display the resulted list. If there is no matching index for the last element
of the list, retain the element as it is.
8. Write a program that
a. accepts a tuple (say, tpl) of numbers from a user.
316 Touchpad Computer Science-XI

