Default Arguments
Completed
Write power(base, exp=2). Read a line with one or two integers: if only one is given print its square, otherwise print base ** exp.
Input
One line: base or base exp.
Output
The result.
Example
Input
5
Output
25
Editor
Python
Hints
exp=2 gives exp a default value.
power(*nums) passes the list items as separate arguments.
Solution explanation
Default values make parameters optional. Never use a mutable default like [] (see the Functional chapter).
Show solution
def power(base, exp=2):
return base ** exp
nums = list(map(int, input().split()))
print(power(*nums))