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

GRADE XII - Python Connectivity with MySQL

  Python Connectivity with MySQL In real-life applications, the data inputted by the user and processed by the application needs to be saved permanently, so that it can be used for future manipulation. Usually, input and output data is displayed during execution but not stored, as it resides in main memory , which is temporary — i.e., it gets erased once the application is closed. This limitation can be overcome by sending the data to be stored in a database , which is made accessible to the user through a Front-End interface . Key Concepts Database A database is an organized collection of data that is stored and accessed electronically from a computer system. DBMS (Database Management System) A DBMS is software that interacts with end-users, applications, and the database to capture and analyze data. Front-End The Front-End is the user interface of the application, responsible for input/output interaction with the user. Back-End The Back-End refe...

GRADE XII - CSV FILE

CSV FILE (COMMA SEPERATED VALUE) CSV NOTES LINK :  CSV NOTES - CLICK HERE Writing data to a CSV file involves the following steps: Import the csv module Open the CSV file in write mode ( "w" ) using open() Create the writer object Write the data into the file using the writer object Close the file using close() writerow() Method This method is used to write a single row to a CSV file. It takes a sequence (list or tuple) as its parameter, and writes the items as a comma-separated line in the file. You do not need to add a newline character (\n) — it automatically places the end-of-line marker.     EXAMPLE 1: import csv  # Importing the csv module # CSV file opened using relative path csv_fobj = open("emp.csv", "w")   # Writer object created wtr_obj = csv.writer(csv_fobj) # Record with field heading is written wtr_obj.writerow(["Empno", "Name", "Salary"]) # Records with data are...