Default Arguments

Sort by

recency

|

222 Discussions

|

  • + 1 comment

    I don't understand what they are asking for, much less come up with a solution. This question doesn't seem to focus so much on your knowledge of default arguments. Seems like there is an issue on object initialization (based on reading comments). Apparently, the goal of this question is to try to trip you up, not actually test your knowledge or teach you anything.

  • + 0 comments

    in example 0, it prints "0, 2, 4" for the first even 3. but the explanation says it is going to be 2,4,6. but it says example 0 is correct. anyone else notice that inconsistency or am i missing something?

  • + 0 comments

    This one was tough

  • + 0 comments
    class EvenStream:
        def __init__(self):
            self.current = 0
    
        def get_next(self):
            val = self.current
            self.current += 2
            return val
    
    
    class OddStream:
        def __init__(self):
            self.current = 1
    
        def get_next(self):
            val = self.current
            self.current += 2
            return val
    
    
    def print_from_stream(n, stream):
        for _ in range(n):
            print(stream.get_next())
    q = int(input())
    
    for _ in range(q):
        stream_name, n = input().split()
        n = int(n)
    
        if stream_name == "even":
            stream = EvenStream()
        else:
            stream = OddStream()
    
        print_from_stream(n, stream)
    
  • + 1 comment
    def print_from_stream(n, stream=EvenStream()):
        stream.__init__()
        for _ in range(n):
            print(stream.get_next())