1 2 3
Sometimes you want to handle a variable number of parameters (like print
does)
You can add a *
before your parameter name so that it accepts a variable number of arguments, gathering them into a tuple
maximum
*values
values
You have 10 minutes to complete the quiz
main()
, no need for test casesAllowed built-in functions: round()
, input()
, float()
, str()
, int()
, len()
, range()
min_max
*values
values
def min_max(*values):
max = None
min = None
for v in values:
if max == None or v > max:
max = v
if min == None or v < min:
min = v
return min, max
def main():
assert min_max(1) == (1, 1)
assert min_max(3,1) == (1, 3)
assert min_max(2,4,6) == (2, 6)
assert min_max() == (None, None)
print("Passed all tests")
main()
Passed all tests