Worksheet Pythontour
Worksheet Pythontour
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")