Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Computer Science Practice Questions-1, Functions

This document contains practice questions on functions in computer science, aimed at preparing students for their Board Examination. It includes various types of questions, such as identifying valid function headers, understanding void functions, and analyzing code outputs. Additionally, it provides guidelines for answering the questions and submitting queries to teachers.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Computer Science Practice Questions-1, Functions

This document contains practice questions on functions in computer science, aimed at preparing students for their Board Examination. It includes various types of questions, such as identifying valid function headers, understanding void functions, and analyzing code outputs. Additionally, it provides guidelines for answering the questions and submitting queries to teachers.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Computer Science

Practice Questions
Topic: Functions
Full Marks 20
NOTE
• You are advised against doing selective study.
• The questions given above are sample questions for practice prior to Board Examination.
• Although Answer Keys will be provided within 2-3 days of posting of these questions, you are
advised to answer them yourself.
• In case you have queries regarding a portion of the chapters being revised here you may send
your query to your teacher through Chat section in MS Teams.

1. Which of the following is a valid function header? 1


a. def interest (P, R=10, T):
b. def circle area (rad):
c. def loop ( n ):
d. def sort ( [5, 9, 3, 1, 7] )
2. Which of the following is a valid statement? 1
a. A void function does not have a parameter list
b. A void function does not return anything
c. A void function neither receives any parameters nor returns any value
d. A void function has no function body
3. During a function call, keyword arguments 1
a. Should be placed before positional arguments
b. Can be placed anywhere as arguments
c. Should be placed after positional arguments
d. Can be placed in-between positional arguments
4. Default parameter in a function: 1
a. Is used when no argument is passed for that parameter
b. Is used irrespective of whether an argument is passed to the function or not
c. Should be placed on the left of positional parameters
d. Are a must in the parameter list
5. The global keyword: 1
a. Is used to access a global variable inside a function
b. Is used to place a variable in the global name space
c. Is used to declare a function parameter as global
d. Is used to call a function with a global argument
6. Find the output of the following code: 2
def find( a, b ):
global c
a = a+b
b = b+c
c = c+a
print(a, b, c)
#main
a = 3
b = 5
c = 10
find( a, b )
print(a, b, c)
7. Find the output of the following code: 2
def calc( x, y=5, z=6 ):
p = x+y * z
r = p + x+y+z//3
return p, r
#main
a = calc( 1, 8, 3 )
print(a)
b = calc( 4 )
print(b)

8. Find the output of the following code: 2


def new( S ):
T = ''
n = len(S)
for i in range(n):
if S[i].isdigit():
T += S[i]*2
elif S[i].isspace():
T += '#'
elif S[i].isalpha():
T += S[i].upper()
else:
T += '*'
print(T)
#main
new('@5.3% Disc')
9. Find the output of the following code: 2
def modify( s ):
n = ''
for c in s:
if c.isupper():
n += chr(ord(c) + 2)
elif c.islower():
n += chr(ord(c) - 2)
elif c.isdigit():
n += str( int(c) * 2 )
else:
n += '2'
return n
#main
print( modify('Fri@23') )
10. Find the output of the following code: 2
def F1(n):
if n in [2, 7, 4, 9]:
return 5*n - 2
elif n in [3, 5, 1, 6]:
return 3*n + 2
else:
return 2*n - 2
#main
num = 2854
new = 0
while num != 0:
d = num%10
new = new + F1(d)
num //= 10
print(new)
11. Rectify the errors in the following code and rewrite the code by underlining the corrections made: 2
def func(n, t r=6):
while t<n
if t = r: break
t += 1
else:
t = t+r
return t
12. Define a function that receives a list and reverses all the even numbers in the list and creates a new
list. The new list is returned. If received list is [24, 71, 864, 37], then returned list is [42, 71, 468, 37]. 3

Date of posting answer key: 22/01/2025

You might also like