Skip to main content

Posts

Showing posts from May, 2025

GRADE XII - Assignment Booklet : Python Functions

  CHAPTER – FUNCTIONS IN PYTHON Assignment Booklet (P- 53) - ANSWER KEY   Q1.  Write a menu driven program to accept an integer and do the following on user's choice 1. multiplication Table 2. Factors 3. Check Prime or Composite Write UDF for each option Sol: # Function to print multiplication table def multtable(num):     for i in range(1, 11):         print(num, "*", i, "=", num * i) # Function to print all factors def factors(num):     print("Factors of", num, "are:")     for i in range(1, num + 1):         if num % i == 0:             print(i) # Function to check prime or composite def prime(num):     if num < 2:         print(num, "is neither prime nor composite.")     else:         for i in range(2, num // 2 + 1):             if num % i == 0:         ...

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 followi...

FUNCTIONS - LOCAL & GLOBAL VARIABLES

 Local Variables In Python, a local variable is a variable that is defined inside a function and can only be used within that function . It exists only while the function is running , and it disappears after the function finishes execution . def greet():     message = "Hello, World!"   # 'message' is a local variable     print(message) greet() # print(message)   # This would cause an error because 'message' is not accessible here NOTES: message is a local variable because it's defined inside the greet() function. You cannot access message outside the function . Local variables are created when the function is called and are destroyed when the function ends. Why use local variables? To keep data private to the function. To avoid conflicts with variables in other parts of the program.   Global Variables A global variable is a variable that is defined outside of...