First compute the factorial: 5!=5×4×3×2×1=120. Then last_digit(n) returns n%10, so last_digit(factorial(5)) gives 120%10=0. The order of function composition matters: the inner call supplies the result to the outer call.
**Answer: A.**
A: **Correct:** Computes 5! first and then extracts its final digit.
B: **Incorrect:** Computes factorial(5), since last_digit(5)=5, returning 120 rather than 0.
C: **Incorrect:** Multiplies 5 by 120 and returns 600, not its last digit.
D: **Incorrect:** Computes factorial(5%10)=factorial(5)=120.
Creating acc1 and acc2 executes __init__ twice, so the shared class counter is 2. The deposit changes only acc1's balance from 1000 to 1500. acc2 starts at 500; withdrawing 200 is permitted, reduces its balance to 300, and returns True. Hence the values are 2, True, 300. A successful method call does not create another account.
**Answer: C.**
A: **Incorrect:** There are two accounts and the withdrawal succeeds.
B: **Incorrect:** The withdrawal succeeds and reduces acc2's balance to 300.
C: **Correct:** Matches the account count, Boolean result and remaining balance.
D: **Incorrect:** Depositing or withdrawing does not increment the constructor's counter.
The condition checks inequality, not equality. For r, the first inner comparison against y already succeeds, so append r and break the inner loop. The same happens for e versus y and d versus y. The outer loop continues through all characters of red, giving ['r','e','d']. This is not a test for common letters between the two strings.
**Answer: A.**
A: **Correct:** Each outer character is appended at its first unequal inner character.
B: **Incorrect:** Incorrectly omits e even though e differs from the first y.
C: **Incorrect:** Would fit a common-letter idea, but the code tests inequality.
D: **Incorrect:** The code appends characters from colors1, not all of colors2.
Ignoring the space, hello world contains l three times, o twice, and each other letter once. The dictionary records these frequencies. The second loop scans sorted keys and keeps a new key only for a strictly greater frequency. l reaches the maximum of 3, so it prints `l`.
**Answer: B.**
A: **Incorrect:** h occurs only once.
B: **Correct:** l occurs three times, the maximum frequency.
C: **Incorrect:** o occurs twice, fewer than l.
D: **Incorrect:** w occurs once.
range(1,6) visits 1,2,3,4,5. The if/elif/else chain contributes +2 for 1, +2 for 2, -3 for 3, +4 for 4, and +10 for 5. The running totals are 2,4,1,5,15. Thus it prints 15. Only one branch executes for each integer.
**Answer: A.**
A: **Correct:** Matches 2+2-3+4+10=15.
B: **Incorrect:** Does not include all five contributions correctly.
C: **Incorrect:** Does not account for the subtraction at i=3 correctly.
D: **Incorrect:** This is the total before processing i=5.
The dictionary counts characters in 'machinelearningwithpython'. n appears three times, while i, a, e, h, r and t each appear twice and the other letters once. The maximum-frequency scan therefore selects n. Sorting keys only controls the winner in a frequency tie; it does not change the counts.
**Answer: B.**
A: **Incorrect:** i occurs twice, less often than n.
B: **Correct:** n occurs three times and has the unique maximum.
C: **Incorrect:** e occurs twice.
D: **Incorrect:** a occurs twice.
The requirement has two parts: select products with price strictly greater than 500, and output only their names. A correctly combines tuple unpacking, the >500 filter and the name expression. C performs the same logic with an explicit loop and append. The sample alone cannot distinguish >500 from >=500 because it contains no price exactly 500; the stated requirement must be checked.
**Answer: A, C.**
A: **Correct:** Correctly returns the name for each tuple whose price is greater than 500.
B: **Incorrect:** Includes a product priced exactly 500, violating the strict condition.
C: **Correct:** The loop tests price>500 and appends only the name.
D: **Incorrect:** Tests equality to 500 and returns whole tuples rather than the required names.
Each constructor creates its own grades dictionary and registers the object in the shared students dictionary. There are two distinct names, so the registry has two entries. Priya has marks 90 and 85; her method uses integer division, (90+85)//2=87. Rahul has only Math:75. The registry stores objects, not name strings, and one student's marks do not populate the other's dictionary.
**Answer: A, B, D.**
A: **Correct:** Priya and Rahul are the two registry entries.
B: **Correct:** Integer division of 175 by 2 gives 87.
C: **Incorrect:** Rahul has only Math:75; Science:85 belongs to Priya.
D: **Correct:** Priya's dictionary contains exactly Math:90 and Science:85.
E: **Incorrect:** The value under Rahul is a StudentGrade instance, not a string.
Select **all** that apply.
**Note**
• If a value is passed to
, it reads that many number of characters from
the current position of the file pointer.
• The
method moves the position of the file pointer to the given number
of chars after the start of the file.
6406536956301.
The first line of the output is
.
6406536956302.
The second line of the output is
.
6406536956303.
The second line of the output is
.
6406536956304.
There are 5 lines in the output.
6406536956305.
The output contains empty lines.
Published solution
The file contains Line1 through Line10 joined by newline characters. Two readline calls skip Line1 and Line2. read(5) returns 'Line3', leaving its newline unread. The next readline consumes that newline; read(10) then returns 'Line4\nLine', which prints across two lines. seek(0) resets the pointer; read(5) returns 'Line1'. A readline consumes its newline and another skips Line2, so the last read(5) returns 'Line3'. The displayed lines are Line3, Line4, Line, Line1, Line3: five lines with no blank line.
**Answer: A, C, D.**
A: **Correct:** The first two readline calls position the first print at Line3.
B: **Incorrect:** The second printed line is Line4, not Line5.
C: **Correct:** The next read starts at Line4 after consuming Line3's newline.
D: **Correct:** One print contains an embedded newline, giving five output lines from four print calls.
E: **Incorrect:** The embedded newline separates nonempty text; no output line is empty.
Each recursive call counts uppercase letters at the two ends, then recurses on the interior slice lst[1:-1]. The pairs are A/G (2), b/f (0), C/E (2), and central d (0). Total=2+0+2+0=4. The single-element base case counts the central element only once.
**Answer: 4.**
Start total=10 and count=0. Values 2, '10' and 5 convert successfully to integers, adding 7,15 and 10, so total becomes 42. Converting 'abc' raises ValueError before result is assigned for that iteration. The handler adds 1 to count and subtracts 3 from total, leaving total=39,count=1. The final print is total+count=40.
**Answer: 40.**
The recursion compares the first and last character, rejecting immediately if they differ, and otherwise checks the inside substring. 11, 121, 151 and 99 read the same forwards and backwards. 12 fails its first comparison. Therefore four numbers pass and count is 4. Converting each number to a string makes character indexing possible.
**Answer: 4.**
accumulated is extended rather than reset. For i=0 it becomes [10], and its sum 10 is added. For i=1, [10,20] is appended, making [10,10,20] with sum 40. For i=2, [10,20,30] is appended, making [10,10,20,10,20,30] with sum 100. The running total adds 10+40+100=150. The nested loop re-sums all accumulated values each time.
**Answer: 150.**
helper(x) returns x squared. nested_call(0) returns zero; each positive call adds its own square to the result for n-1. Thus nested_call(4)=4²+3²+2²+1²+0=16+9+4+1=30. Defining the helper inside the function does not add extra terms; its returned value is added once per non-base call.
**Answer: 30.**
Based on the above program, answer the given subquestions.
What does the first
statement output?
6406536956311.
97
6406536956312.
93
6406536956313.
288
6406536956314.
98
Published solution
The first loop iterates over dictionary keys and adds their corresponding values. The total is d['P']+d['C']+d['B']=97+93+98=288. It sums all marks, rather than selecting only the largest mark.
**Answer: C.**
A: **Incorrect:** 97 is P's individual value.
B: **Incorrect:** 93 is C's individual value.
C: **Correct:** 288 is the sum of the three values.
D: **Incorrect:** 98 is the maximum individual value, not the sum.
Based on the above program, answer the given subquestions.
What is printed in the second line?
6406536956315.
P
6406536956316.
C
6406536956317.
B
6406536956318.
None
Published solution
max(d,key=d.get) iterates over the keys but compares d.get(key), their associated values. B has 98, which exceeds P's 97 and C's 93. The expression returns the winning key, so the second print is B rather than 98.
**Answer: C.**
A: **Incorrect:** P's 97 is below B's 98.
B: **Incorrect:** C's 93 is below the other values.
C: **Correct:** B has the largest associated value.
D: **Incorrect:** The dictionary is nonempty and max returns its winning key.
Based on the above program, answer the given subquestions.
What is the element at position [0][2] in
?
Published solution
The function changes only diagonal positions matrix[i][i]. Position [0][2] is off the main diagonal, so it remains the original value 3. For completeness, i=0 swaps diagonal values 1 and 9, i=1 swaps the centre with itself, and i=2 swaps 9 and 1 back. The loop therefore restores the original diagonal too.
**Answer: 3.**
Based on the above program, answer the given subquestions.
What is the value of the second line of output?
Published solution
The diagonal-swap loop visits both ends of every pair, so each noncentral swap is undone later. For the 3×3 matrix, the final diagonal is again 1,5,9. g multiplies these diagonal entries, starting from prod=1: 1×1×5×9=45. It is a product, not the trace (sum), and not a product of every matrix element.
**Answer: 45.**