[go: up one dir, main page]

0% found this document useful (0 votes)
71 views27 pages

XII Function Output

Uploaded by

RIZWAN N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views27 pages

XII Function Output

Uploaded by

RIZWAN N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

1.

Program 1
def ChangeVal (M,N):
for i in range(N):
if M[i]%5 == 0:
M[i]//=5
if M[i]%3 == 0:
M[i]//= 3
L=[ 25,8,75,12]
ChangeVal (L,4)
for i in L:
print(i,end="#")

Output:
5#8#5#4#

2. Program 2:

def update(x=10):
x+=15
print("x=",x)
x=20
update()
print("x=",x)

Output:
x= 25
x= 20

3. Program 3:

s="WELCOME"
def change(T):
t="HELLO"
print(T,end="@")
change(s)
print(s)

Output:
WELCOME@WELCOME
4. Program 4:

def funstr(s):
t=""
for i in s:
if i.isdigit():
t=t+i
return t
x="LEO MASTER"
y=funstr(x)
print(x,y,sep="*")

Output:
LEO MASTER*

5. Program 5:
v=100
def change(n):
global v
v,n=n,v
print(v,n,sep="#",end="@")
change(20)
print(v)

Output:
20#100@20

6. Program 6:
def listchange():
for i in range(len(l)):
if l[i]%2==0:
l[i]=l[i]*5
if l[i]%3==0:
l[i]=l[i]*10
else:
l[i]=l[i]*20
l=[2,6,9,10]
listchange()
for i in l:
print(i,end="$")

Output:
200$300$90$1000$

7. Program 7:
def power(b,p):
y=b**p
return y
def calcsquare(x):
a=power(x,2)
return a
n=10
result=calcsquare(n)+power(3,3)
print(result)

Output:
127

8. Program 8:
p=5
def sum(q,r=2):
global p
p=r+q**2
print(p,end="#")
a=2
b=10
sum(a,b)
sum(r=5,q=1)

Output:
14#6#

9. Program 9:
def func(message,num=1):
print(message*num)
func('python')
func('Programming',2)
Output:
python
ProgrammingProgramming

10. Program 10:

def fun(s):
k=len(s)
m=""
for i in range(0,k):
if(s[i].isupper()):
m=m+s[i].lower()
elif s[i].isalpha():
m=m+s[i].upper()
else:
m=m+'bb'
print(m)
fun('Zion&AlwinGroup')

Output:
zIONbbaLWINgROUP

11. Program 11:

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)

Output:
250 # 150
250 # 100
130 # 100

12. Program 12:


def check(n1=1,n2=2):
n1=n1+n2
n2+=1
print(n1,n2)
check()
check(1,3)
check(4)
Output:
33
44
63

13. Program 13:


def diff(n1,n2):
if n1>n2:
return n1-n2
else:
return n2-n1
num=[10,23,14,54,32]
for cnt in range(4,0,-1):
a=num[cnt]
b=num[cnt-1]
print(diff(a,b),"#",end='')

Output:
22 #40 #9 #13 #

14. Program 14:

def interest(prnc,time=2,rate=0.10):
return(prnc*time*rate)
print(interest(6100,1))
print(interest(5000,rate=0.05))
print(interest(5000,3,0.12))
print(interest(time=4,prnc=5000))

Output:
610.0
500.0
1800.0
2000.0

15. Program 15:

num=1
def fun():
return num
print(num)
print(fun())
print(num)

Output:
1
1
1

16. Program 16:

num=1
def fun():
num=10
return num
print(num)
print(fun())
print(num)

Output:
1
10
1
17. Program 17:

num=1
def fun():
global num
num=10
return num
print(num)
print(fun())
print(num)

Output:
1
10
10

18. Program 18
def display():
print("hello",end=' Am ')
display()
print("here!")
display()
print("everywhere!")

Output:
hello Am here!
hello Am everywhere!

19. Program 19
a=10
y=5
def fun():
global a,y
y=a
a=2
print("y=",y,"a=",a)
print('a+y+',a+y)
return a+y
print("y=",y,"a=",a)
print(fun())
print("y=",y,"a=",a)
Output:
y= 5 a= 10
y= 10 a= 2
a+y+ 12
12
y= 10 a= 2

20. Program 20

def increment(n):
n.append([4])
return n
l=[1,2,3]
m=increment(l)
print(l,m)

Output:
[1, 2, 3, [4]] [1, 2, 3, [4]]

21. Program 21

def increment(n):
n.append([49])
return n[0],n[1],n[2],[3]
l=[23,35,47]
m1,m2,m3,m4=increment(l)
print(l)
print(m1,m2,m3,m4)
print(l[3]==m4)

Output:
[23, 35, 47, [49]]
23 35 47 [3]
False

22. Program 22

v=25
def fun(ch):
v=50
print(v,end=ch)
v*=2
print(v,end=ch)
print(v,end="*")
fun("!")
print(v)
Output:
25*50!100!25

23. Program 23
a=10
def myfunction():
a=20
return
print('a=',a)
Output:
a= 10

24. Program 24
def my_function(country = "Norway"):
print("I am from " + country)
my_function("Sweden")
my_function("India")
my_function()
my_function("Brazil")

Output:
I am from Sweden
I am from India
I am from Norway
I am from Brazil

25. Program 25
def my_function(food):
for x in food:
print(x)
fruits = ["apple", "banana", "cherry"]
my_function(fruits)

Output:
apple
banana
Cherry
26. Program 26:

def my_function(**kid):
print("His last name is " + kid["lname"])
my_function(fname = "Tobias", lname = "Refsnes")

Output:

His last name is Refsnes

27. Program 27:


def my_function(child3, child2, child1):
print("The youngest child is " + child3)
my_function(child1 = "Emil", child2 = "Tobias", child3 = "Linus")

Output:

The youngest child is Linus

28. Program 28
def my_function(*kids):
print("The youngest child is " + kids[2])
my_function("Emil", "Tobias", "Linus")

Output:

The youngest child is Linus

29. Program 29

def my_function(fname, lname):


print(fname + " " + lname)
my_function("MsDhoni","iconic 7")

Output:

MsDhoni iconic 7
30. Program 30:
def my_function(x):
return 5 * x
print(my_function(3))
print(my_function(5))
print(my_function(9))

Output:
15
25
45

31. Program 31:


def tri_recursion(k):
if(k > 0):
result = k + tri_recursion(k - 1)
print(result)
else:
result = 0
return result
print("\n\nRecursion Example Results")
tri_recursion(6)

Output:
Recursion Example Results
1
3
6
10
15
21

32. Program 32:


def power (b, p):
y = b ** p
return y

def calcSquare(x):
a = power (x, 2)
return a
n=5
result = calcSquare(n)
print (result)
Output:
25

33. What will the following function return?

def addEm(x, y, z):


print (x + y + z)

34. What will be the output displayed when addEM() is called/executed?


def addEm(x, y, z):
return x + y + z
print (x+ y + z)

35. What will be the output of the following programs?

num = 1
def myfunc():
return num
print(num)
print(myfunc())
print(num)

Output:
1
1
1

36. What will be the output of the following programs?


num = 1
def myfunc():
num = 10
return num
print (num)
print(myfunc())
print(num)
Output:
1
10
1

37. What will be the output of the following programs?


num = 1
def myfunc ():
global num
num = 10
return num
print (num)
print(myfunc())
print(num)

Output:
1
10
10

38. What will be the output of the following programs?


def display():
print("Hello", end = ' ')
display()
print("there!")

Output:
Hello there!

39. Program 39:


def cal(a,b,c):
return a*3,b*3,c*3
val=cal(10,12,14)
print(type(val))
print(val)

Output:
<class 'tuple'>
(30, 36, 42)

40. Program 40:


def outer_fun(a, b):
def inner_fun(c, d):
return c + d
return inner_fun(a, b)
return a
result = outer_fun(5, 10)
print(result)
Output:
15

41. Program 41:


def display(**kwargs):
for i in kwargs:
print(i)

display(emp="Kelly", salary=9000)

Output:
Emp
salary

42. Program 42:


def fun1(name, age=20):
print(name, age)

fun1('Emma', 25)
Output:
Emma 25

43. Program 43:

def display_person(**args):
for i in args:
print(i)

display_person(name="Emma", age="25")

Output:
Name
age

44. Program 44:


def add(a, b):
return a+5, b+5

result = add(3, 2)
print(result)

Output:
(8,7)

45. Program 45:

def fun1(num):
return num + 25
num=fun1(5)
print(num)

Output:
30

46. Program 46:


def display(num):
num.append([27])
return(num[1],num[2],num[3])
list1=[6,12,27]
n1,n2,n3=display(list1)
print(list1)

Output:
[6, 12, 27, [27]]

47. Program 47:

x=['ab','cd']
for i in x:
i.upper()
print(x)
Output:
['ab','cd']

48. Program 48:


a=3
b=4
c=a**b+5
print(c)
def test(a,b):
s=a+b*2
print(s)
test(12,5)

Output:
86
22

49. Program 49:


d1={}
d1[2]=85
d1[1]=[22,23,24]
print(d1[1][1])

Output:
23

50. Program 50:


def test(a):
for i in a:
print(i)
test((3,4,5,3,7))
Output:
3
4
5
3
7

51. Program 51:


def func(a=1,b=2):
a=a+b
b+=1
print(a,b)
func(b=4,a=5)

Output:
9 5

52. Program2:
i=0
def change(i):
i=i+1
return i
change(1)
print(i)

Output:
0

53. Program 53:

z=100
def f():
global z
print("z is:",z)
z=50
print("new value of global is:",z)
f()
print("Value of z is:",z)

Output:
z is: 100
new value of global is: 50
Value of z is: 50

54. Program 54:


def cube():
print(n*n*n)
n=10
cube()
print(cube())

Output:
1000
1000
None

55. Program 55:


def Alter(x, y = 10, z=20):
sum=x+y+z
print(sum)
Alter(10,20,30)
Alter(20,30)
Alter(100)

Output:
60
70
130

56. Program 56:

def check():
num=50
print(num)
num=100
print(num)
check()
print(num)

Output:
100
50
100
57. Program 57:
def check():
global num
num=1000
print(num)
num=100
print(num)
check()
print(num)

Output:
100
1000
1000

58. Program 58:


def display(s):
l = len(s)
m=""
for i in range(0,l):
if s[i].isupper():
m=m+s[i].lower()
elif s[i].isalpha():
m=m+s[i].upper()
elif s[i].isdigit():
m=m+"$"
else:
m=m+"*"
print(m)
display("EXAM20@cbse.com")

Output:
exam$$*CBSE*COM

59. Program 59:


def Alter(M,N=50):
M=M+N
N=M-N
print(M,"@",N)
return M
A=200
B=100
A = Alter(A,B)
print(A,"#",B)
B = Alter(B)
print(A,’@’,B)
Output:
300 @ 200
300 # 100
150 @ 100
300 @ 150

60. Program 60:


def Total(Number=10):
Sum=0
for C in range(1,Number+1):
if C%2==0:
Continue
Sum+=C
return Sum
print(Total(4))
print(Total(7))
print(Total())

Output:
4
16
25

61. Program 61:


X = 100
def Change(P=10, Q=25):
global X
if P%6==0:
X+=100
else:
X+=50
Sum=P+Q+X
print(P,'#',Q,'$',Sum)
Change()
Change(18,50)
Change(30,100)

Output:
10 # 25 $ 185
18 # 50 $ 318
30 # 100 $ 480
62. Program 62:
a=100
def show():
global a
a=200
def invoke():
global a
a=500
show()
invoke()
print(a)

Output:
500

63. Program 63:


def drawline(char='$',time=5):
print(char*time)
drawline()
drawline('@',10)
drawline(65)
drawline(chr(65))

Output:
$$$$$
@@@@@@@@@@
325
AAAAA

64. Program 64:


def Updater(A,B=5):
A = A // B
B=A%B
print(A,'$',B)
return A + B
A=100
B=30
A = Updater(A,B)
print(A,'#',B)
B = Updater(B)
print(A,'#',B)
A = Updater(A)
print(A,'$',B)

Output:
3$3
6 # 30
6$1
6#7
1$1
2$7

65. Program 65:


def Fun1(num1):
num1*=2
num1 = Fun2(num1)
return num1
def Fun2(num1):
num1 = num1 // 2
return num1
n = 120
n = Fun1(n)
print(n)
Output:
120

66. Program 66:


X = 50
def Alpha(num1):
global X
num1 += X
X += 20
num1 = Beta(num1)
return num1
def Beta(num1):
global X
num1 += X
X += 10
num1 = Gamma(num1)
return num1
def Gamma(num1):
X = 200
num1 += X
return num1
num = 100
num = Alpha(num)
print(num,X)

Output:
420 80

67. Program 67:


def Fun1(mylist):
for i in range(len(mylist)):
if mylist[i]%2==0:
mylist[i]/=2
else:
mylist[i]*=2
list1 =[21,20,6,7,9,18,100,50,13]
Fun1(list1)
print(list1)

Output:
[42, 10.0, 3.0, 14, 18, 9.0, 50.0, 25.0, 26]

68. Program 68:


def func1(list1):
for x in list1:
print(x.lower(),end="#")
func1(["New","Dehli"])

Output:
new#dehli#

69. Program 69:


def abc(x,y=60):
return x+y
a=20
b=30
a=abc(a,b)
print(a,b)
b=abc(a)
print(a,b)
a=abc(b)
print(a,b)

Output:
50 30
50 110
170 110

70. Program70:
def Execute(M):
if M%3==0:
return M*3
else:
return M+10;
def Output(B=2):
for T in range (0,B):
print(Execute(T),"*",end="")
print()
Output(4)
Output()
Output(3)
Output:.
0 *11 *12 *9 *
0 *11 *
0 *11 *12 *

71. Program 71:


def ChangeIt(Text,C):
T=""
for K in range(len(Text)):
if Text[K]>='F' and Text[K]<='L':
T=T+Text[K].lower();
elif Text[K]=='E' or Text[K]=='e':
T=T+C;
elif K%2==0:
T=T+Text[K].upper()
else:
T=T+T[K-1]
print(T)
OldText="pOwERALone"
ChangeIt(OldText,"%")
Output:
PPW%RRllN%

72. Program 72:


def disp(str):
m=' '
for i in range(0,len(str)):
if(str[i].isupper()):
m=m+str[i].lower()
elif str[i].islower():
m=m+str[i].upper()
else:
if i%2==0:
m=m+str[i-1]
else:
m=m+"@"
print(m.swapcase())
disp('StudyBag$2021')

Output:
StudyBagG@2@2

73. Program 73:


def makenew(mystr):
newstr = " "
count = 0
for i in mystr:
if count%2 ==0:
newstr = newstr+i.lower()
else:
if i.islower():
newstr = newstr+i.upper()
else:
newstr = newstr+i
count +=1
newstr = newstr+mystr[:3]
print ("The new string is :", newstr)
makenew("cbseEXAMs@2022")
Output:
The new string is :
cBsEeXaMs@2022cbs

74. Program 74:

def prog(name):
for x in name:
if x.isalpha():
print('Alphabet')
elif x.isdigit():
print('Digit')
elif x.isupper():
print('Capital Letter')
else:
print('Hello All')
prog('1.^2.*/3.+-')
Output:
Digit
Hello All
Hello All
Digit
Hello All
Hello All
Hello All
Digit
Hello All
Hello All
Hello All

75. Program 75:


def changer(p,q=10):
p=p/q
q=p%q
print(p,"#",q)
return p
a=200
b=20
a=changer(a,b)
print(a,"$",b)
a=changer(a)
print(a,"$",b)
Output:
10.0 # 10.0
10.0 $ 20
1.0 # 1.0
1.0 $ 20

76. Program 76:

def div(lst,n):
for i in range(0,n):
if lst[i]%5==0:
lst[i]+=5
else:
lst[i]=lst[i]//2
lt=[45,20,23,54,5]
div(lt, len(lt))
for i in lt:
print(i,end='#')
Output:
50#25#11#27#10#

You might also like