Computer Science
Computer Science
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.