WK 4 (1) - 02032024 - 120151

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

HE PIONEER SCHOOL-CBSE

Nagercoil
Worksheet-4
Subject - Computer Science(Python functions)
GRADE:XII Date:04/03/2024
36.

37.What is the output of the below program?

a)
Hello World!
Hello World!
b)
‘Hello World!’
‘Hello World!’
c)
Hello
Hello
d) None of the mentioned
38.What is the output of the below program ?
x = 50
def func(x):
#print(‘x is’, x)
x=2
#print(‘Changed local x to’, x)
func(x)
print(‘x is now’, x)
a) x is now 50
b) x is now 2
c) x is now 100
d) None of the mentioned

39.What is the output of the below program?

a)
a is 7 and b is 3 and c is 10
a is 25 and b is 5 and c is 24
a is 5 and b is 100 and c is 50
b)
a is 3 and b is 7 and c is 10
a is 5 and b is 25 and c is 24
a is 50 and b is 100 and c is 5
c)
a is 3 and b is 7 and c is 10
a is 25 and b is 5 and c is 24
a is 100 and b is 5 and c is 50
d) None of the mentioned
40.What is the output of the below program?

a) 2 b) 3 c) The numbers are equal


d) None of the mentioned
41.Which of the following refers to mathematical function?
a) sqrt
b) rhombus
c) add
d) fact
42.What is the output of the below program?

a) 212
32
b) 9
27
c) 567
98
d) None of the mentioned
43.What is the output of the below program?

a) 6
15
b) 6
100
c) 123
12345
d) None of the mentioned
44.What is the output of the following piece of code?

a)4 b)5 c)1 d)An exception is thrown


45.Spot the errors and rewrite the corrected codes.
total=0;
def sum(arg1, arg2) :
total = arg1 + arg2
print("Total:", total)
return total
sum (10,20)
print("Total:" total)
46.What will be the output of the following expression in python?
print ( round (100.0 / 4 + (3 + 2.55) , 1 ) )

a) 30.0 b) 30.5 c) 30.6 d) 30.1

47.What will be the output of the following code:

48.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: [2, 0, 5, 0, 1, 0, 0]

The indexList will have: [0,2,4]

49.Write definition of a function Count_How_Many(Data, item) to count and display number


of times the value of item is present in the list Data. (Note: don’t use the count() function)
For example :
If the Data contains [101,102,107,105,102,103,104,102] and item contains 102
The function should display 102 found 3 Times.
50.Write a function, length(words), that takes a string as an argument and returns a list
containing the length of each word of a string.
For example, if the words are “ Hello program", the list will have [5,7]
51.Write a function STR_PALIN(Str) that takes string as an argument and returns if a string
is a palindrome
or not (A string is called palindrome if it reads the same backwards as forward). (2)
For example, if the string is
Str = Naman
Then output should be:
The given string Naman is a palindrome.
52.Write a function REPLACE_VOWEL(St) that takes string as an argument and returns a
string in which all
vowels are replaced with ‘*’.
For example, if the string is
St= Message your token number
Then output should be:
St = M*ss*g* y**r t*k*n n*mb*r
53.Write a Python statement for each of the following tasks using BUILT-IN
functions/methods only.
(i) To find the minimum value from a list named ‘Numbers’.
(ii) To find and print the length of words from the list.
54.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
55.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)
56.Predict the output:

57.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]

58.def fun1(x, y):


x=x+y
y=x–y
x=x–y
print(‘a=’,x)
print(‘b=’,y)
a=5
b=3
fun1(a,b)
59.def div5(n):
if n%5==0:
return n*5
else:
return n+5
def output(m=5):
for i in range(0,m):
print(div5(i),’@’,end=” “)
print(‘n’)
output(7)
output()
output(3)
60.def func(x,y=100):
temp = x + y
x += temp
if(y!=200):
print(temp,x,x)
a=20
b=10
func(b)
print(a,b)
func(a,b)
print(a,b)
61. def get(x,y,z):
x+=y
y-=1
z*=(x-y)
print(x,’#’,y,’#’,z)
def put(z,y,x):
x*=y
y+=1
z*=(x+y)
print(x,’$’,y,’$’,z)
a=10
b=20
c=5
put(a,c,b)
get(b,c,a)
put(a,b,c)
get(a,c,b)
62.Error finding:
def in(x,y):
x=x + y
print(x.y)
x*=y
print(x**y)
63.What are the parts of functions? Explain with a suitable example.
64.predict the output:

65. Predict the output:

You might also like