CS Xii
CS Xii
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 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)
P1 = [20]
P2 = 4
P3 = "school"