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

RANDOM MODULE

Q1. FIND THE OUTPUT:

import random

for i in range(5):

    num = random.randint(1, 100)

    print(num)

Q2.

import random

for i in range(5):

    print(random.randrange(2, 21, 2))

Q3.

import random

fruits = ["Apple", "Mango", "Banana", "Orange"]

print(random.choice(fruits))

Q4.

import random

Val = random.randint(1, 3) + random.randint(1, 2)

print(Val)

(A) 2            (B) 1            (C) 6           (D) 7

Q5.

import random

Words = ["GO", "TO", "SLEEP", "NOW"]

N = random.randint(1, 3)

print(Words[N], end="#")

print(Words[N-1], end="#")

(A) TO#GO# (B) SLEEP#TO# (C) GO#TO# (D) NOW#GO#

Q6.

import random

fruits = ["Apple", "Orange", "Banana", "Grape"]

chosen_fruit = random.choice(fruits)

print(len(chosen_fruit), chosen_fruit[0], sep='-')

(A) 5-Apple    (B) 6-O    (C) 5-A    (D) Banana-6

Q7.

import random

word = "PYTHON"

char = random.choice(word)

print(char, word.index(char))

(A) P 0                     (B) T 2

(C) N 5                     (D) All of the above

Q8.

import random

for i in range(random.randrange(2, 5)):

    print(i, end='@')

(A) 0@1@2@3@4@                      (B) 0@1@

(C) 2@3@4@                                 (D) 1@2@3@

Q9.

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#

Q10.

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="&")

 Q11.

 import random

points = [30, 50, 20, 40, 45]

begin = random.randint(0, 3)

last = random.randint(2, 3)

for c in range (begin, last + 1):

    print(points[c], "#", end = "")

  Q12.

import random

languages = ['Python', 'Java', 'PHP', 'HTML', 'C++']

pos=random.randint(1,4)

for c in range(0, pos+1):

    print(languages[c], end="&")




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 XI | DESIGN THINKING & INNOVATION (848) | INTRO | CH-1

  DESIGN THINKING &  INNOVATION (848)  INTRODUCTION LINK : INTRODUCTION PPT PPT LINK Notes: Design Thinking and Innovation Grade XI Introduction Section   I. What is Design? (0.1.1) Definitions from Experts: John Maeda: "Design is solution to a problem". Saul Bass: "Design is thinking made visual". Charles Eames:   “Design is a plan for arranging elements in such a way as best to accomplish a particular purpose.” Steve Jobs:  "Design is not just what it looks like and feels like. Design is how it works". Prof. Sudhakar Nadkarni:  "Essentials of design are— purity, precision, details". Design is a way of understanding needs, identifying problems, and creating appropriate and innovative solutions. It is not only about appearance, but also about usefulness and sustainability. Design is explained as something that helps solve problems and make a positive difference. Key ...