pyforschool.
com
Output Questions
Question 1
Find the output of the following program.
def fun(s):
n = len(s)
m=''
for i in range(0, n):
if (s[i] >= 'a' and s[i] <=
'm'):
m = m + s[i].upper()
elif (s[i] >= 'n' and s[i] <=
'z'):
m = m + s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m + '#'
print(m)
fun('Gini%Jony')
Show the answer.
gIiI#jJon
Question 2.
Find the output of the following program.
def Withdef(HisNum = 30):
for i in range(20,HisNum+1,5):
print(i, end=" ")
print()
def Control(MyNum):
MyNum = MyNum + 10
Withdef(MyNum)
YourNum = 25;
Control(YourNum);
Withdef();
print("Number = " ,YourNum)
Show the answer.
Question 3.
Find the output of the following program.
def Position(C1, C2, C3):
C1[0] = C1[0] + 2
C2 = C2 + 1
C3 = "python"
P1 = [20]
P2 = 4
P3 = "school"
Position(P1, P2, P3);
print(P1, ", ", P2, ", ", P3)
Show the answer.
Question 4.
Find the output of the following program.
def Change(num1 ,num2=50):
num1 = num1 + num2
num2 = num1 - num2
print(num1, "#", num2)
return (num1)
n1 = 150
n2 = 100
n1=Change(n1,n2)
print(n1,"#",n2)
n2=Change(n2)
print(n1,"#",n2)
Show the answer.
Question 5.
Find the output of the following program.
def increment(marks):
p=[]
for m in marks:
m = m + 5
if (m>100):
m=100
p.append(m)
return p
def decrement(marks):
for i in range(0,len(marks)):
marks[i] = marks[i] - 5
if (marks[i]<0):
marks[i]=0
a = [45,55,96,85]
a = increment(a)
print(a)
decrement(a)
print(a)
Show the answer.
Question 6.
Find the output of the following program.
frequency = { }
list = ['a','b','c','a','c']
for index in list:
if index in frequency:
frequency[index]+=1
else:
frequency[index]=1
print(len(frequency))
print(frequency)
Show the answer.
Question 7.
Find the output of the following program.
string = "subordinate"
vowel = "aeiou"
count = 0
for letter in string:
if letter in vowel:
count = count + 1
print(count)
Show the answer.
Question 8.
Observe the following python code carefully
and obtain the output, which will appear on
the screen after execution of it.
a = "Guido Van Rossum"
a = a.split()
b = a[0][0]+". "+a[1][0]+". "+a[2]
print (b)
Show the answer.
Question 9.
Find the output of the following program.
Str1 = "EXAM2020"
Str2 = ""
I=0
while I<len(Str1):
if Str1[I]>="A" and Str1[I]<="M":
Str2=Str2+Str1[I+1]
elif Str1[I]>="0" and Str1[I]<="9":
Str2=Str2+ (Str1[I-1])
else:
Str2=Str2+"*"
I=I+1
print(Str2)
Show the answer.
Question 10.
Find the output of the following program.
Str1 = "EXAM2020"
Str2 = ""
I=0
while I<len(Str1):
if Str1[I]>="A" and Str1[I]<="M":
Str2=Str2+Str1[I+1]
elif Str1[I]>="0" and Str1[I]<="9":
Str2=Str2+ (Str1[I-1])
else:
Str2=Str2+"*"
I=I+1
print(Str2)
Show the answer.
Question 11.
Find the output of the following program.
def Alter(P=15,Q=10):
P=P*Q
Q=P/Q
print (P,"#",Q)
return Q
A=100
B=200
A=Alter(A,B)
print (A,"$",B)
B=Alter(B)
print (A,"$",B)
A=Alter(A)
print (A,"$",B)
Show the answer.
Question 12.
Find the output of the following program.
List = ["P",20,"R",10,"S",30]
Times = 0
Alpha = ""
Sum = 0
for I in range(1,6,2):
Times = Times + I
Alpha = Alpha + List[I-1]+"#"
Sum = Sum + List[I]
print(Times,Sum,Alpha)
Show the answer.