'''Bad: Use lowercase letter at the beginning of a comment'''
# get user input
n,*vals=map(int,input().split())
'''Good: Always begin a comment with an uppercase letter'''
# Get user input
n, *vals = map(int, input().split())
'''Bad: Ambiguous variable name with explanation'''
s = num1 + num2 # Sum of the two numbers
'''Good: Just use explanatory variable names without comments as explanation'''
sum_of_nums = num1 + num2
'''Bad: Worthless comments'''
# Add num1 with num2 and assign the result to sum_of_nums
sum_of_nums = num1 + num2
'''Good: Just remove those useless comments'''
sum_of_nums = num1 + num2
'''Worse: Misleading / Outdated comments'''
def process_nums(nums):
"""Return odd nums in the sequence."""
return filter(lambda num: num % 2 == 0, nums)
'''Good: Use correct / updated comments'''
def process_nums(nums):
"""Return even nums in the sequence."""
return filter(lambda num: num % 2 == 0, nums)
'''Bad'''
# Get the length of a string
def get_text_length(s, log_output=False):
if not isinstance(s, str):
raise TypeError("Argument `s` must be of type 'str'")
result = len(s)
if log_output:
print(result)
return result
'''Good'''
def get_text_length(/, string: str, *, log_output: bool = False) -> int:
"""Get the length of a string.
:param string: The string to be calculated.
:param log_output: Log output to console or not (default False).
:returns: The length of the string.
:raises TypeError: Raised when argument `string` is not a string.
>>> get_text_length('foobar')
6
>>> get_text_length(42)
Traceback (most recent call last):
...
TypeError: Argument `string` must be of type 'str'
"""
if not isinstance(s, str):
raise TypeError("Argument `string` must be of type 'str'")
result = len(s)
if log_output:
print(result)
return result