0% found this document useful (0 votes)
2 views1 page

Class Test Functions

The document outlines several Python functions to perform specific tasks: LShift shifts elements in a list to the left, INDEX_LIST retrieves indices of non-zero elements, countNow displays names of places longer than five characters, lenWords returns the lengths of words in a string, showGradas assigns grades based on average scores, and Puzzle replaces every Nth character in a word with an underscore. Each function is accompanied by sample inputs and expected outputs for clarity. The document serves as a guide for implementing these functions in Python.

Uploaded by

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

Class Test Functions

The document outlines several Python functions to perform specific tasks: LShift shifts elements in a list to the left, INDEX_LIST retrieves indices of non-zero elements, countNow displays names of places longer than five characters, lenWords returns the lengths of words in a string, showGradas assigns grades based on average scores, and Puzzle replaces every Nth character in a word with an underscore. Each function is accompanied by sample inputs and expected outputs for clarity. The document serves as a guide for implementing these functions in Python.

Uploaded by

aaa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Write a function LShift(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 left.


Sample Input Data of the list
Arr= [ 10,20,30,40,12,11], n=2
Output
Arr = [30,40,12,11,10,20]

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]
The indexList will have - [0,1,3,5]

Write a function countNow(PLACES) in Python, that takes the dictionary, PLACES as an argument and displays the
names (in uppercase)of the places whose names are longer than 5 characters.
For example, Consider the following dictionary
PLACES={1:"Delhi",2:"London",3:"Paris",4:"New York",5:"Doha"}
The output should be:
LONDON
NEW YORK

Write a function, lenWords(STRING), that takes a string as an argument and returns a tuple containing length of each
word of a string.
For example, if the string is "Come let us have some fun", the tuple will have (4, 3, 2, 4, 4, 3)

Write a user defined function in Python named showGradas(S) which takes the dictionary S as an
[Link] dictionary, S contains Name: [Enq, Math, Scianca] as key:value pairs. The function
displays the corresponding grade obtained by the students according to the following grading rules :
Avaraqa of Enq,Math,Scianca Grade
>=90 A
<90 but >=60 B
<60 c
For example : Consider the following dictionary
S={"AMIT": [92,86,64] ," ":[65,42,43] ,"DAVID": [92,90,88])
The output should be :
AMIT - B NAGMA- C
DAVID- A

Write a user defined function in Python named Puzzle (W 1N) which takes the argument W as an
English word and N as an integer and returns the string where every Nth alphabet of the word w is replaced
with an underscore ( "_").
For example : ifw contains the word "TELEVISION" and N is 3, then the function should return the
string "TE_EV_SI_N". Likewise for the word "TELEVISION" if N is 4, then the function should
return "TEL_VIS_ON".

You might also like