0% found this document useful (0 votes)
116 views2 pages

Functions Worksheet-1 Programs From Sample Papers

Uploaded by

leyah.pvt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
116 views2 pages

Functions Worksheet-1 Programs From Sample Papers

Uploaded by

leyah.pvt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ASPAM INDIAN INTERNATIONA SCHOOL-SHARJAH

FUNCTIONS WORKSHEET
SUBJECT: COMPUTER SCIENCE
Note: These are the sample programs from CBSE sample papers, write the answers for
all the questions in your notebook.
1. Write a function first_list (N), where N is the list of elements passed as argument to the
function. The function returns another list names selected_element that stores the all even
values of first_list.
For example: if first_list contains [24,13,18,0,11,25,32]
selected_element wil have [24,18,32].
2. Write a function INDEX_LIST(L), where L is the list of elements passed as argument to
the function. The function returns another list named ‘indexList’ that stores the indices of
all Non-Zero Elements of L.
For example: If L contains [12,4,0,11,0,56] than
The indexList will have - [0,1,3,5]
3. Write a function AdjustList(L), where L is a list of integers. The function should reverse
the contents of the list without slicing the list and without using any second list.
Example: If the list initially contains 2, 15, 3, 14, 7, 9, 19, 6, 1, 10,
then after reversal the list should contain 10, 1, 6, 19, 9, 7, 14, 3, 15, 2
4. Write a function INDEX_LIST(S), where S is a string. The function returns a list named
‘indexList’ that stores the indices of all vowels of S.
For example: If S is "Computer",
then indexList should be [1,4,6].
5. Python funtion oddeve(L) to print positive numbers in a list L.
Example: Input: [4, -1, 5, 9, -6, 2, -9, 8]
Output: [4, 5, 9, 2, 8].
6. Write a function listchange(Arr,n)in Python, which accepts a list Arr of numbers and n is
an numeric value depicting length of the list. Modify the list so that all even numbers
doubled and odd number multiply by 3 .
Sample Input Data of the list: Arr= [ 10,20,30,40,12,11],
n=6
Output: Arr = [20,40,60,80,24,33].
7. Write definition of a method/function AddOddEven(VALUES) to display sum of odd
and even values separately from the list of VALUES.
For example : If the VALUES contain [15, 26, 37, 10, 22, 13]
The function should display Even Sum: 58 Odd Sum: 65.
8. Write the definition of a function Reverse(X) in Python to display the elements in reverse
order such that each displayed element is twice of the original element (element *2) of
the List X in the following manner:
For example, if List X contains 7 integers as follows:
i/p: [4,8,7,5,6,2,10]
After executing the function, the array content should be displayed as follows:
o/p: [20,4,12,10,14,16,8]
9. Write a function INDEX_LIST(L), where L is the list of elements passed as argument to
the function. The function returns sum of odd nos in list .

Page 1 of 2
10. Write a function in Shift(Lst), Which accept a List ‘Lst’ as argument and swaps the
elements of every even location with its odd location and store in different list
eg. if the array initially contains 2, 4, 1, 6, 5, 7, 9, 2, 3, 10
then it should contain 4, 2, 6, 1, 7, 5, 2, 9, 10, 3.
11. Define a function ZeroEnding(SCORES) to add all those values in the list of SCORES,
which are ending with zero (0) and display the sum.
For example : If the SCORES contain [200, 456, 300, 100, 234, 678]
The sum should be displayed as 600.
12. Write a Python function SwitchOver(Val) to swap the even and odd positions of the
values in the list Val. Note : Assuming that the list has even number of values in it.
For example : If the list Numbers contain [25,17,19,13,12,15]
After swapping the list content should be displayed as [17,25,13,19,15,12].
13. Write a python Function that accepts a string and calculates the number of uppercase
letters and lowercase letters.
Sample String : Python ProgrammiNg
Expected Output:
Original String : Python ProgrammiNg
No. of Upper case characters : 3
No. of Lower case characters :14.
14. Write a function R_Shift(Arr,n) in Python, which accepts a list Arr of numbers and n is a
numeric value by which all elements of the list are shifted to right and the last element
removed should be added in the begining.
Sample Input Data of the list Arr=[ 1,2,3,4,5,6], n=2 Output Arr = [5, 6, 1, 2, 3, 4]
15. Write definition of a function How_Many(List, elm) to count and display number of
times the value of elem is present in the List. (Note: don’t use the count() function)
For example : If the Data contains [205,240,304,205,402,205,104,102]
and elem contains 205
The function should display 205 found 3 Times
16. Write definition of a Method MSEARCH(STATES) to display all the state names from a
list of STATES, which are starting with alphabet M.
For example: If the list STATES contains[“MP’,”UP”,”MH”,”DL”,”MZ”,”WB”]
The following should get displayed MP MH MZ
17. Write a function listchange(Arr)in Python, which accepts a list Arr of numbers, the
function will replace the even number by value 10 and multiply odd number by 5.
Sample Input Data of the list is: a=[10,20,23,45]
listchange(a,4)
output : [10, 10, 115, 225
18. Write a function that takes two numbers and return that has maximum one’s digit. (for eg
if 491 and 278 are passed it will return 278 as it has got maximum one’s digit).
19. Write a function Interchange (num) in Python, which accepts a list num of integers, and
interchange the adjacent elements of the list and print the modified list as shown below:
(Number of elements in the list is assumed as even)
Original List: num = [5,7,9,11,13,15]
After Rearrangement num = [7,5,11,9,15,13].

Page 2 of 2

You might also like