0% found this document useful (0 votes)
48 views3 pages

CS Xii

The document contains questions about functions in Python. It asks to define functions, differentiate between formal and actual parameters, local and global variables, positional and default arguments. It also asks to find the output of code snippets using functions and global variables.

Uploaded by

Parth Purwar
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)
48 views3 pages

CS Xii

The document contains questions about functions in Python. It asks to define functions, differentiate between formal and actual parameters, local and global variables, positional and default arguments. It also asks to find the output of code snippets using functions and global variables.

Uploaded by

Parth Purwar
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/ 3

CLASS – XII

SUBJECT – COMPUTER SCIENCE (083)


CHAPTER – 3 [FUNCTIONS]
ASSIGNMENT

Q 1. Rewrite the following code after removing error. Underline each correction done
by you.
def SI(p,t=2,r): DEF execmain( ):
return (p*r*t)/100 x = input ( “Enter a number”)
If (abs(x)=x) :
Print (“You Entered a
def chksum : positive number ..”)
x = input ( “Enter a number”) else:
if (x % 2 = 0) : x=*−1
for i range ( 2 * x ): print(“Number made
print (i) positive:”x)
loop else: execmain()
print ( “#”)

def checkval:
x = raw_input(“Enter a number”)
def Tot(Number) #Method to find Total
if x % 2 = 0 :
Sum=0
print x,”is even”
for C in Range (l, Number+l):
else if x<0 :
Sum+=C
print x,”should be positive”
RETURN Sum
else ;
print Tot[3] #Function Calls
print x,”is odd”
print Tot[6]

Q 2. Define functions. Why there is a need to use a function in a program.


Q 3. Differentiate between the following with the help of an example:
(a) Actual and Formal Parameters
(b) Local and Global Variables
(c) Positional and Default arguments
Q 4. Write the type of tokens from the following :
if roll_no Else int
Q 5. Name the Python Library modules which need to be imported to invoke the
following functions:
(i) sin( ) (ii) randint ( ) (iii) uniform( ) (iv) ceil( )
Q 6. Find and write the output of the following:
a=10
def call():
global a
a=15
b=20
print(a)
call()

Q 7. How can you access a global variable inside the function, if function has a variable
with same name?
Q 8. Write the output of the following code:
(a)
x = 50
def func(x):
print('x is', x)
x=2
print('Changed local x to', x)
func(x)
print('x is now', x)

(b)
x = 50
def func():
global x
print('x is', x)
x=2
print('Changed global x to', x)
func()
print('Value of x is', x)

(c)
def func(a, b=5, c=10):
print('a is', a, 'and b is', b, 'and c is', c)
func(3, 7)
func(25, c = 24)
func(c = 50, a = 100)
(d)
a=10
b=20
def change():
global b
a=45
b=56
change()
print(a)
print(b)

Q 9. Find the output of the following:


def Change(P ,Q=30):
P=P+Q
Q=P-Q
print( P,"#",Q)
return (P)
R=150
S=100
R=Change(R,S)
print(R,"#",S)
S=Change(S)

Q 10. Find the output of the following:


def Position(C1, C2, C3):
C1[0] = C1[0] + 2
C2 = C2 + 1
C3 = "python"

P1 = [20]
P2 = 4
P3 = "school"

Position(P1, P2, P3);


print(P1, ", ", P2, ", ", P3)

You might also like