Default Arguments

Sort by

recency

|

215 Discussions

|

  • + 0 comments
    def print_from_stream(n, stream=None):
        if stream is None:
            stream = EvenStream()
        for _ in range(n):
            print(stream.get_next())
    
  • + 0 comments

    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

  • + 0 comments

    Here is HackerRank Default Arguments in Python solution - https://programmingoneonone.com/hackerrank-default-arguments-problem-solution-in-python.html

  • + 0 comments

    the problem is poorly described, the task itself is simple, but it is not clear what the author means...

  • + 0 comments

    class EvenStream: def init(self): self.current = -2

    def get_next(self):
        self.current += 2
        return self.current
    

    class OddStream: def init(self): self.current = -1

    def get_next(self):
        self.current += 2
        return self.current
    

    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())