0% found this document useful (0 votes)
24 views2 pages

Worksheet Pythontour

1. Variables defined inside a function become local variables. A local variable exists only inside its function. 2. Global variables can be accessed and modified inside functions. To modify a global variable inside a function, it must be declared global inside the function. 3. Formal and actual parameters do not need to have the same names but their number and type must match. Formal parameters act as local variables inside a function.

Uploaded by

Shriya Bharadwaj
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)
24 views2 pages

Worksheet Pythontour

1. Variables defined inside a function become local variables. A local variable exists only inside its function. 2. Global variables can be accessed and modified inside functions. To modify a global variable inside a function, it must be declared global inside the function. 3. Formal and actual parameters do not need to have the same names but their number and type must match. Formal parameters act as local variables inside a function.

Uploaded by

Shriya Bharadwaj
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/ 2

GRADE XII COMPUTER SCIENCE CHAPTER 1,2,3 WORKSHEET-1

Find the output of the following: 12. _________________means a variable pointing


to a value of certain type can be made to point
1. x,x=100,200
to value/object of different type.
print(x)
y,y=x+100,x+200
13. Variable used inside a function become its:
print(y)
a. Local variable
b. Global variable
2. x = 5
c. Reference variable
print(x > 3 and x < 10)
d. None of these
3. x = 5
14. What will be the output of the following
print(x > 3 or x < 4)
code?
a=10
4. v="""computer\ def myfunction():
science\ a=20
programming""" return
print(v) print('a=',a)
a. a=20
5. v="""computer b. a=10
science c. Syntax error
programming""" d. Value error
print(v)
15. What is not true about formal and actual
6. v="computer parameters?
science a. Their Number and type must match
programming" b. Need not be given in same order
print(v) c. Their names must be identical
d. All statements are true
7. print('sun','moon','stars')
16. In Python, functions are
8. print('sun','moon','stars',sep="*") a. Always called by passing reference
b. Always called by passing value
9. def greet(*names):
c. May be called by passing reference
print ('Hello ', names[0], ', ', names[1], ',
', names[3]) or value
greet('Steve', 'Bill', 'Yash') d. None of these

10. def sum(a, b): 17. Write the output:


return a + b

total=sum(10, 20)
print(total)
total=sum(5, sum(10, 20))
print(total)

11.
x=10
def myfunction(): 18. Write the output:
print ('x inside function: ', x)
x=20 a=10
x=x*2 def myfunction():
print ('x inside function: ', x) a=20
myfunction() return
print ('x in global scope: ',x) print(myfunction())
print('a=',a)
19. 26.
x=5
def f1():
def f1():
x=100
global x
return x
x=4
f1()
def f2(a,b):
print(x)
global x
return a+b+x
20.
f1()
def f1():
total = f2(1,2)
global x
print(total)
x+=1
27.
print(x)
Read the following Python code carefully and point
x=12
out the global variables?
f1()
y, z = 1, 2
print("x")
def f():
21.
global x
x=10 x = y+z
def myfunction(): print(x)
print ('x inside function: ', x) f()
x=5 28.
print('x inside function',x) def myfunc():
myfunction() global x
print ('x in global scope: ',x) x = "fantastic"
22.
myfunc()
x=12 print("Python is " + x)
def f1(a,b=x): 29.
print(a,b) def myFun1(*argv):
x=15 for i in argv:
print (i)
f1(4)
23. print("Result of * args: ")
myFun1('Hello', 'Welcome', 'to', 'TCIS')
def f():
30.
global a a=10
print(a) def myfunction():
a = "hello" a=20
print(a) b=9
a = "world" return a,b
f() s=myfunction()
print(a) print("Returned value",s)
24. print(type(s))
def f1(a,b=[]): print('a=',a)
b.append(a) 31.
return b def my_function(child3, child2, child1):
print("The youngest child is ",child3)
print(f1(2,[3,4]))
25.
my_function(child1 = "Eena", child2 = "Meena",
def f(p, q, r): child3 = "Deeka")
global s
p = 10 32.
q = 20 def my_function(country = "Norway"):
r = 30 print("I am from " , country)
s = 40
print(p,q,r,s) my_function("Sweden")
p,q,r,s = 1,2,3,4 my_function("India")
f(5,10,15) my_function()
my_function("Brazil")

You might also like