From 3bf137f823bddabef36745008d06a5fac086fe1e Mon Sep 17 00:00:00 2001 From: Ian Mayther Date: Mon, 12 Apr 2021 20:57:32 -0700 Subject: [PATCH] Completed update of streams-exercise --- stream_exercise.py | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/stream_exercise.py b/stream_exercise.py index c0cf5a5..199f4ce 100644 --- a/stream_exercise.py +++ b/stream_exercise.py @@ -46,22 +46,29 @@ def __init__(self, stream): self._stream = stream def process(self): - """ - TODO: Implement the `process` method, as described above. - - :return: int - """ + """ + TODO: Implement the `process` method, as described above. + + :return: int + """ - count = 0 # How many two-digit numbers the `process` method has added - # together. - total = 0 # The running total of sums. + count = 0 # How many two-digit numbers the `process` method has added + # together. + total = 0 # The running total of sums. - # TODO: WRITE CODE HERE: + # TODO: WRITE CODE HERE: + while count < 10 and total < 200: + digits = self._stream.read(2) + if len(digits) < 2: + break + + count +=1 + total += int(digits) - # Just some example syntax, you can read two digits from the head of the - # stream using the following code: - # - # digits = self._stream.read(2) + # Just some example syntax, you can read two digits from the head of the + # stream using the following code: + # + # digits = self._stream.read(2) - return count + return count