updated taxi simulator

This commit is contained in:
Luciano Ramalho
2015-02-10 19:08:24 -02:00
parent c6df60bb66
commit 7ec5f62376
7 changed files with 265 additions and 4 deletions

42
control/adder/adder.py Normal file
View File

@@ -0,0 +1,42 @@
import sys
def ask():
prompt = '>'
while True:
response = input(prompt)
if not response:
return 0
yield response
def parse_args():
yield from iter(sys.argv[1:])
def fetch(producer):
gen = producer()
next(gen)
yield from gen
def main(args):
if args:
producer = parse_args
else:
producer = ask
total = 0
count = 0
gen = fetch(producer())
while True:
term = yield from gen
term = float(term)
total += term
count += 1
average = total / count
print('total: {} average: {}'.format(total, average))
if __name__ == '__main__':
main(sys.argv[1:])