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