Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import sys
- totalPrice = 0
- numberOfItems = 0
- oldKey = None
- print ("{:<70} {:<20} {:<20}\n\n".format( "Winery Name","Total Revenue","Average Revenue"))
- for line in sys.stdin:
- data_mapped = line.strip().split("\t")
- if len(data_mapped) != 2:
- # Something has gone wrong. Skip this line.
- continue
- thiskey, currentPrice = data_mapped
- if oldKey and oldKey != thiskey:
- print ("{:<70} {:<20} {:<20}".format( oldKey,totalPrice,totalPrice/numberOfItems))
- oldKey = thiskey;
- totalPrice = 0
- numberOfItems=0
- oldKey = thiskey
- numberOfItems+=1
- totalPrice += float(currentPrice)
- if oldKey != None:
- print ("{:<70} {:<20} {:<20}".format( oldKey,totalPrice,totalPrice/numberOfItems))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement