You are viewing a single comment's thread. Return to all comments →
The logic for adding parentheses is based on order of operations.
Division and multiplication are executed in left to right order unless parentheses are used to modify the order.
Say we have s = 'aaa' and n = 10
s = 'aaa'
n = 10
Case 1 (correct, with parens): s.count('a') *( n//(len(s)) ) --> 3 * (10 // 3) --> 3 * 3 --> 9
s.count('a') *( n//(len(s)) )
3 * (10 // 3)
3 * 3
9
Case 2 (without parens): s.count('a') *( n//(len(s)) ) --> 3 * 10 // 3 --> 30 // 3 --> 10
3 * 10 // 3
30 // 3
10
Seems like cookies are disabled on this browser, please enable them to open this website
Repeated String
You are viewing a single comment's thread. Return to all comments →
The logic for adding parentheses is based on order of operations.
Division and multiplication are executed in left to right order unless parentheses are used to modify the order.
Say we have
s = 'aaa'
andn = 10
Case 1 (correct, with parens):
s.count('a') *( n//(len(s)) )
-->3 * (10 // 3)
-->3 * 3
-->9
Case 2 (without parens):
s.count('a') *( n//(len(s)) )
-->3 * 10 // 3
-->30 // 3
-->10