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

Python Functions Worksheet for Grade XII

Uploaded by

dbmsjava8056
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)
11 views1 page

Python Functions Worksheet for Grade XII

Uploaded by

dbmsjava8056
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

OXALISS INTERNATIONAL SCHOOL (CBSE)

COMPUTER SCIENCE (083)


WORKSHEET
GRADE : XII CHAPTER : WORKING WITH FUNCTIONS

1. 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 index List will have - [0,1,3,5]
2. Write a function that receives two string arguments and checks whether they are same-length
strings (returns True in this case otherwise False).

3. 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

4. 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)

5. Write a program that implements a user defined function that accepts Principal Amount, Rate, Time,
Number of Times the interest is compounded to calculate and displays compound interest. (Hint:
CI=P*(1+r/n)nt)

6. Write a program that contains user defined functions to calculate area, perimeter or surface area
whichever is applicable for various shapes like square, rectangle, triangle, circle and cylinder. The user
defined functions should accept the values for calculation as parameters and the calculated value should
be returned. Import the module and use the appropriate functions.

Common questions

Powered by AI

To find the indices of all non-zero elements in a list, a function named `INDEX_LIST` can be created. This function will iterate over the list, check each element to see if it is non-zero, and if so, add its index to a new list called `indexList`. For example, given a list L = [12, 4, 0, 11, 0, 56], the function would return [0, 1, 3, 5], as these are the indices of the non-zero elements .

The program should define user-specific functions for each shape, each accepting relevant parameters required for the calculation, such as side lengths or radii. For example, functions could calculate area and perimeter for squares and rectangles, perimeter and area for circles, and surface area for cylinders. After defining these functions, the program would import them as a module and use them to perform calculations on the given parameters, returning the results accordingly .

A function designed to check if two strings are of the same length should first receive the strings as arguments. It should then use the `len()` function to obtain the length of each string, and compare these lengths. If they are equal, the function returns `True`; otherwise, it returns `False` .

The function `lenWords` should take a string as its argument, split the string into a list of words using the `split()` method, and then calculate the length of each word using the `len()` function. The function should compile these lengths into a tuple and return it. For instance, for the input "Come let us have some fun", the function would return (4, 3, 2, 4, 4, 3).

The function to calculate compound interest should use the formula CI = P*(1 + r/n)^(nt), where P is the Principal Amount, r is the annual interest rate, n is the number of times the interest is compounded per year, and t is the time the money is invested or borrowed for, in years. These parameters should be passed to the function to compute and return the compound interest .

A function named `countNow` should accept the dictionary of place names as an argument. It will iterate over the dictionary values and check the length of each place name. If a name is longer than 5 characters, the function will convert it to uppercase and add it to the output. For example, given PLACES={1:"Delhi",2:"London",3:"Paris",4:"New York",5:"Doha"}, the output would be: LONDON NEW YORK .

You might also like