functions
functions
1. def fun2(name,age):
print(age,name)
func2(25,”Ramesh”)
2. def fun3(a,b,c):
return a+1,b+2,c+3 #if more than 1 values are returned than it will be as
tuple
t=fun3(10,20,30)
print(t)
3. def fun2(list1):
for x in list1:
print(x.upper(),end="#")
fun2(["Rajesh","Kumar"])
4. def fun2(num1,num2):
for x in range(num1,num2):
if x%4==0:
print(x,end="")
fun2(10,20)
5. def prog(email):
for x in email.split("."):
if x.isalpha():
print("alphabet")
elif x.isdigit():
print("digit")
elif x.isupper():
print("upper")
else:
print("all the best")
prog("rajesh.123.yahoo")
6. def check(x,y):
if x != y:
return x+5
else:
return y+10
print(check(10,5))
7.
8.
9.
def my_func(var1=100, var2=200):
var1+=10
var2 = var2 - 10
return var1+var2
print(my_func(50),my_func())
print(value, end="#")
display(20)
print(value)
a. Delhi#Mumbai#Chennai#Kolkata#
b. Mumbai#Chennai#Kolkata#Mumbai#
c. Mumbai# Mumbai #Mumbai # Delhi#
d. Mumbai# Mumbai #Chennai # Mumbai
16. What possible output(s) are expected to be displayed on screen at the time of execution of the
program from the following code?
Also specify the minimum values that can be assigned to each of the variables BEGIN and LAST.
import random
VALUES = [10, 20, 30, 40, 50, 60, 70, 80]
BEGIN = random.randint (1, 3)
LAST = random.randint(2, 4)
for I in range (BEGIN, LAST+1):
print (VALUES[I], end = "-")
ANSWERS
1. Ans :- Ramesh, 25
3. RAJESH#KUMAR#
4. 1216
5. alphabet
digit
alphabet
6. 15
7. I and IV
8. True
True
True
9. 250 300
10. 18
11. 50#5
12. b. Mumbai#Chennai#Kolkata#Mumbai#
13. 5#8#5#4#
14. pYTHOnN#.
15. 3 5 5