0% found this document useful (0 votes)
3 views3 pages

Computer Science

The document contains a series of programming questions and code snippets related to Python, focusing on output prediction, function definitions, and list manipulations. It includes tasks such as determining outputs of given code, writing functions for specific operations, and modifying lists based on certain conditions. The questions cover various topics including string manipulation, list indexing, and the use of built-in functions.

Uploaded by

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

Computer Science

The document contains a series of programming questions and code snippets related to Python, focusing on output prediction, function definitions, and list manipulations. It includes tasks such as determining outputs of given code, writing functions for specific operations, and modifying lists based on certain conditions. The questions cover various topics including string manipulation, list indexing, and the use of built-in functions.

Uploaded by

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

OUTPUT QUESTIONS (REVISION) 9.

What is the output of the following Python


statements?
1.Consider following list for python language x=2
L=[13, 3.45, “Tree”, ‘Amar’, [10, 8.91, “Apple”], while x < 9:
456] print(x, end=" '')
x=x+1
What will be the e output of L[–2] ?
10.Find the output of the following code:
2.What does the following code print? [2+3] Name="PythoN3.1"
for i in range ( 1 , 10 ): R=""
for j in range ( 1 , 10 ): for x in range(len(Name)):
print(i * j,) if Name[x].isupper():
print() R=R+Name[x].lower()
elif Name[x].islower():
3.Give the output of the following statements : R=R+Name[x].upper()
>>> str="Honesty is the best policy" elif Name[x].isdigit():
>>> str.replace(‘o’,‘*’) R=R+Name[x-1]
else:
R=R+"#"
print(R)
4.Write the output of the following code snippet
tup = ('geek',)
n=5
for i in range(int(n)): 11. Identify the correct output(s) of the following
tup = (tup,) code. Also write the minimum and the maximum
print(tup)
possible values of the variable b.
5.Write the output of the following Python code: import random
i=5 a="Wisdom"
j=7 b=random.randint(1,6)
x=0 for i in range(0,b,2):
i=i+(j-i) print(a[i],end='#')
x=j+i
print(x,":",i) (A) W# (B) W#i# (C) W#s# (D) W#i#s#
j=j**2
x=j+i 12.Predict the output of the following code:
i=i+1 d = {"apple": 15, "banana": 7, "cherry": 9}
print(i,":",j) str1 = ""
6.What is the output of the following code ? for key in d:
my_list = [“Python”, “Language”] str1 = str1 + str(d[key]) + "@" + “\n”
print(“-”.join(my_list)) str2 = str1[:-1]
print(str2)
7.Write the output of the following Python
statements:
L1, L2 = [10, 15, 20, 25], []
for i in range (len(L1)) : 13.Predict the output of the following code:
L2. insert(i,L1.pop()) line=[4,9,12,6,20]
print (L1, L2,sep="&") for I in line:
for j in range(1,I%5):
8.What will be the output of the following code? print(j,’#’,end=””)
tup1 = (1,2,[1,2],3) print()
tup1[2][1]=3.14
print(tup1)
OUTPUT QUESTIONS (FUNCTIONS) 6.Predict the output of the code given below:
s="welcome2cs"
1.Find and write the output of the following Python n = len(s)
code: m=""
def Change(P ,Q=30): for i in range(0, n):
P=P+Q if (s[i] >= 'a' and s[i] <= 'm'):
Q=P-Q m = m +s[i].upper()
print( P,"#",Q) elif (s[i] >= 'n' and s[i] <= 'z'):
return (P) m = m +s[i-1]
R=150 elif (s[i].isupper()):
S=100 m = m + s[i].lower()
R=Change(R,S) else:
print(R,"#",S) m = m +'&'
S=Change(S) print(m)

2.What will be the output of the following Python 7.Find and write the output of the following Python
code? code:
def Display(str):
V = 25 m=""
def Fun(Ch): for i in range(0,len(str)):
V=50 if(str[i].isupper()):
print(V, end=Ch) m=m+str[i].lower()
V *= 2 elif str[i].islower():
print(V, end=Ch) m=m+str[i].upper()
print (V, end="*") else:
Fun("!") if i%2==0:
print(V) m=m+str[i-1]
else:
3.Write the output of the code given below: m=m+"#"
p=5 print(m)
def sum(q,r=2): Display('[email protected]')
global p
p=r+q**2 8.Find and write the output of the following Python
print(p, end= '#') code:
a=10 def fun(s):
b=5 k=len(s)
sum(a,b) m=" "
sum(r=5,q=1) for i in range(0,k):
if(s[i].isupper()):
4.What will be the output of the following Python m=m+s[i].lower()
code? elif s[i].isalpha():
V = 50 m=m+s[i].upper()
def Change (N): else:
global V m=m+'bb'
print(m)
V, N = N, V
fun('school2@com')
print(V, N, sep="#",end="@")
Change(20)
print(V)
5.What is the output of the following Python code?
def ListChange ( ):
for i in range(len(L)):
if L[i]%2 == 0:
L[i]=L[i]*2
if L[i]%3 == 0:
L[i]=L [i]*3
else:
L[i]=L[i]*5
L = [2,6,9,10]
ListChange()
for i in L:
print(i,end="#")
PROGRAMMING(REVISION) increments all even number by 1 and decrements all
odd numbers by 1. For example,
1.If L1=[1,2,3,2,1,2,4,2, . . . ], and L2=[10,20,30, . L=[10,20,30,40,35,55]
. .], then the answer following using built-in Ouput will be L=[11,21,31,41,34,54]
functions only)
7. Write a function LShift(Ar,n) in python, which
(I) Write a statement to count the accepts a list Arr of numbers and n is a numeric
occurrences of 4 in L1. value by which all elements of the list are shifte4d
to left. For example-
(II) Write a statement to sort the elements
Arr=[30,40,12,11,10,20] and n=2
of list L1 in ascending order. Output will be Arr=[30,40,12,11,10,20]
(III) Write a statement to insert all the
elements of L2 at the end of L1.
(IV) Write a statement to reverse the
elements of list L2.

2. Write a function INDEX_LIST(L), where L is


the list of elements passed as argument to the
function. The function returns another list named
‘indexList’ that stores the indices of all Non-Zero
Elements of L. For example:
If L contains [12, 4, 0, 11, 0, 56]
The indexList will have - [0, 1, 3, 5]

3. Write the definition of a method ZeroEnding


(SCORES) to add all those values in the list of
SCORES, which are ending with zero (0) and
display the sum. For example:
If the SCORES contain [200, 456, 300, 100, 234,
678]
The sum should be displayed as 600

3. Rohit has a list of 10 integers. Write a program


with separate user-defined functions to perform the
specified
operations on this list..

4.Write a function LenWord(String), that takes a


string as an argument and returns a tuple containing
length of each word of a string.
For example, if the string is “Come let us have
some fun”, the tuple will have (4,3,2,4,4,3)

5. Write a function CountNow(Places) in python,


that takes the dictionary , Places as an argument
and displays the names (in uppercase) of the places
whose names are longer than 5 characters. For
example, consider the following dictionary –
Places={1:’Delhi’, 2:’London’, 3:’Paris’, 4:’New
York’, 5: ‘Dhaka’}
The output should be :
LONDON
NEW YORK

6.Write a function EOReplace() in python, which


accepts a list L of numbers. Thereafter, it

You might also like