Skip to main content

GRADE XII - CS - FIND THE OUTPUT - IMPORTANT PRACTICE QUE

 

IMPORTANT 

(PYQ)

1. Find the output :

def ChangeVal(M, N):

    for i in range(N):

        if M[i] % 5 == 0:

            M[i] //= 5

        if M[i] % 3 == 0:

            M[i] //= 3


L = [25, 8, 75, 12]

ChangeVal(L, 4)

for i in L:

    print(i, end='#')


2.What will be the output of the following code?
def Call(P=40, Q=20):
    P = P + Q
    Q = P - Q
    print(P, '@', Q)
    return P

R = 200
S = 100
R = Call(R, S)
print(R, '@', S)
S = Call(S)
print(R, '@', S)

3.What will be the output of the following code?
import random

Colours = ["VIOLET", "INDIGO", "BLUE", "GREEN", "YELLOW", "ORANGE", "RED"]

End = random.randrange(2) + 3   # End = 3 or 4
Begin = random.randrange(End) + 1  # Begin = 1 to End

for i in range(Begin, End):
    print(Colours[i], end="&")

4.What will be the output of the following code?
def Update(X=10):
X += 15
print('X = ', X)
X=20
Update()
print('X = ', X)

5.What will be the output of the following code?
c = 10
def add():
   global c
   c = c + 2
 print(c,end='#')
add()
c=15
print(c,end='%')

(A) 12%15#
(B) 15#12%
(C) 12#15%
(D) 12%15#

6. What will be the output of the following code?
L = [5,10,15,1]
G = 4
def Change(X):
  global G
  N=len(X)
  for i in range(N):
      X[i] += G
      
Change(L)
for i in L:
  print(i,end='$')

7.What will be the output of the following code?
import random
a="Wisdom"
b=random.randint(1,6)
for i in range(0,b,2):
   print(a[i],end='#')

(A) W#         (B) W#i#
(C) W#s#     (D) W#i#s#

8.The code provided below is intended to swap the first and last elements of a given tuple. However, there are syntax and logical errors in the code.
Rewrite it after removing all errors. Underline all the corrections made

def swap_first_last(tup)
    if len(tup) < 2:
        return tup
    new_tup = (tup[-1],) + tup[1:-1] + (tup[0])
return new_tup

result = swap_first_last((1, 2, 3, 4))
print("Swapped tuple:", result)

9.Rao has written a code to input a number and check whether it is prime or not. His code is having errors. Rewrite the correct code and underline the corrections made.

def prime():
n=int(input("Enter number to check :: ")
for i in range (2, n//2):
if n%i=0:
print("Number is not prime \n")
break
else:
print("Number is prime \n’)

10. What will be the output of the following code?
def Diff(N1,N2):
  if N1>N2:
      return N1-N2
  else:
      return N2-N1
 
NUM= [10,23,14,54,32]
for CNT in range (4,0,-1):
 A=NUM[CNT]
 B=NUM[CNT-1]
 print(Diff(A,B),'#', end=' ')

11.What will be the output of the following code?
p=5
def sum(q,r=2):
  global p
  p=r+q**2
  print(p, end= '@@')

a=10
b=5
sum(a,b)                //Positional Argument
sum(r=5,q=1)        //Keyword Argument





Comments

Popular posts from this blog

CS - SORTING/SEARCHING ALGORITHMS

  SORTING ALGORITHMS                       SORTING ALGORITHM PDF LINK #Bubble Sort          ·        The outer loop iterates through the entire array. ·        The inner loop compares adjacent elements and swaps them if they are out of order. ·        The outer loop runs n times, and each pass moves the largest element to its correct position. arr=[3,8,5,2,1] n = len(arr) print(n) for i in range(n):  #traverse through all the elements         # Last i elements are already sorted, no need to check them         for j in range(0, n-i-1):              # Swap if the element found is greater than the next element              if arr[j] > arr[j+1]:               ...

GRADE XI - NESTED FOR LOOP

                                                         NESTED FOR LOOP 1. for var1 in range(3):      print(var1,"OUTER LOOP")          # 0 outer loop       1 outer loop      2 outer loop          for var2 in range(2):                  print(var2+1,"INNER LOOP")    #1  2 inner loop     1  2  inner loop   1 2 inner loop  2. Print the following pattern using for loop: 1  1 2  1 2 3  1 2 3 4  Sol: for r in range(1,5):   #ROWS     for c in range(1,r+1):   #COLUMNS         print(c,end=" ")     print() 3. Print the following pattern using for loop: @  @ @  @ @ @...