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

PYTHON - MYSQL CONNECTIVITY CODE

  #INSERTION OF DATA import mysql.connector mydb = mysql.connector.connect( host="localhost", user="root", passwd="root", database="school" ) print("Successfully Connected") #print(mydb) mycursor=mydb.cursor()   v1=int(input("enter ID:")) v2=input("enter name:") v3=input("enter Gender:") v4=int(input("enter age:")) sql='insert into TEACH values("%d","%s","%s","%s")'%(v1,v2,v3,v4) print(sql) mycursor.execute(sql) mydb.commit() print("record added") #MYSQL Connection code – Deletion on database SOURCE CODE: s=int(input("enter id of TEACHER to be deleted:")) r=(s,) v="delete from TEACH where id=%s" mycursor.execute(v,r) mydb.commit() print("record deleted") MYSQL Connection code – Updation on database SOURCE CODE: import mysql.connector mydb = mysql.connector.c...

REVISION IF CONSTRUCT | CLASS TEST

                                                                                     CLASS TEST 1. Write a Python program that asks the user for their age, gender, and current fitness level (beginner, intermediate, or advanced). Based on this information, suggest a suitable fitness plan using if-else statements. Requirements: Inputs : Age (integer) Gender (male/female) Fitness level (beginner/intermediate/advanced) Outputs : Recommend a fitness plan that includes: Suggested workout duration. Type of exercises (e.g., cardio, strength, flexibility). Rest days. Logic : Use if-else to determine the plan based on conditions such as: Age group (e.g., <18, 18–40, >40). Fitness leve...