We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Debugging
- Default Arguments
- Discussions
Default Arguments
Default Arguments
Sort by
recency
|
215 Discussions
|
Please Login in order to post a comment
this is the solution def print_from_stream(n, stream=EvenStream()): stream.init() for _ in range(n): print (stream.get_next()) print above code in row 18
Here is HackerRank Default Arguments in Python solution - https://programmingoneonone.com/hackerrank-default-arguments-problem-solution-in-python.html
the problem is poorly described, the task itself is simple, but it is not clear what the author means...
class EvenStream: def init(self): self.current = -2
class OddStream: def init(self): self.current = -1
def print_from_stream(n, stream=None): if stream is None: stream = EvenStream() for _ in range(n): print(stream.get_next())
Read input from STDIN
q = int(input()) for _ in range(q): stream_name, n = input().split() n = int(n) if stream_name == "even": print_from_stream(n, EvenStream()) else: print_from_stream(n, OddStream())