python
TOP 5 OUTPUT BASED QUESTIONS OF PYTHON CBSE FOR CLASS 11 AND 12
OUTPUT-BASED QUESTIONS
PYTHON
Q1) Find output the from following code of Python:
import random pick=random.randint(0,3)
city=["Delhi","Mumbai","Chennai","Kolkata"]
for i in city:
for j in range(1,pick):
print(i,end=” “)
print()
DelhiDelhi
MumbaiMumbai
ChennaiChennai
KolkataKolkata
Q2)Write a function LShift(Arr,n) in Python, which accepts a list Arr of numbers and n is a numeric value by which all elements of the list are shifted to left.
Sample Input Data of the list
Arr= [ 10,20,30,40,12,11], n=2
Output
Arr = [30,40,12,11,10,20]
#main Arr=[ 10,20,30,40,12,11]
LShift(Arr,2)
OR
WRITE program to shift elements in a list?
SOL.
#program to shift elements in a list def LShift(Arr,n):
def LShift(Arr,n):
L=len(Arr)
for x in range(0,n):
y=Arr[0]
for i in range(0,L-1):
Arr[i]=Arr[i+1]
Arr[L-1]=y
print(Arr)
#main
Arr=[10,20,30,40,12,11]
LShift(Arr,2)
Q3)Find the output of the following code
numbers=[9,18,27,36]
for num in numbers:
for n in range(1,num%8):
print(n,"#",end=" ")
print()
sol. OUTPUT:
1#
1 # 2 #
1 # 2 # 3 #
Q4) Find the output of the following code.
SOL:
IN PYTHOM SHELL |
.OUTPUT IS:
{'Apple': 7}
{'Apple': 7, 'Banana': 7}
{'Apple': 7, 'Banana': 7, 'Orange': 7}
{'Apple': 7, 'Banana': 7, 'Orange': 7, 'grapes': 7}
OUT PUT OF THIS CODE CHANGES :
f={}
f1=['Apple', 'Banana', 'Orange', 'grapes']
for i in f1:
f[i]=7
print(f)
OUTPUT IS:
{'Apple': 7, 'Banana': 7, 'Orange': 7, 'grapes': 7}
Q5) Find the output of following.
def fun(s):
k=len(s)
print(k)
m=""
for i in range(0,k):
if (s[i].isupper()):
m=m+s[i].lower()
elif (s[i].islower()):
m=m+s[i].upper()
else:
m=m+'bb'
print(m)
#main
fun('school12@com')
SOL
output is:
Post a Comment
0 Comments