Question 97 of 97
Q.Write a python method/function Swapper(Numbers) to swap the first half of the content of a list Numbers with second half of the content of list Numbers and display the swapped values. Note : Assuming that the list has even number of values in it. For example : If the list Numbers contains [35,67,89,23,12,45] After swapping the list content should be displayed as [23,12,45,35,67,89]
(OR)
Write a python method/function Count3and7(N) to find and display the count of all those numbers which are between 1 and N, which are either divisible by 3 or by 7. For example : If the value of N is 15 The sum should be displayed as 7 (as 3,6,7,9,12,14,15 in between 1 to 15 are either divisible by 3 or 7)
Sikkim CbseCBSE Class XII Board 2019Subjective· 2mImportance★★★★★
100% · 97/97 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Part (a) swaps the first half of a list with its second half and prints the result ([23,12,45,35,67,89]); Part (b) counts and displays how many numbers from 1 to N are divisible by 3 or 7 (7 for N=15).
Part (a)
With an even-length list, element i in the first half pairs with element i + h in the second half, where h = len(Numbers)//2. Swap each such pair in place, then display.
def Swapper(Numbers):
h = len(Numbers) // 2
for i in range(h):
Numbers[i], Numbers[i + h] = Numbers[i + h], Numbers[i]
print(Numbers)
Swapper([35, 67, 89, 23, 12, 45])
Trace (h = 3): swap index 0↔3, 1↔4, 2↔5 → [23, 12, 45, 35, 67, 89].
[23, 12, 45, 35, 67, 89] …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.