Advertisement
Arfizato

Untitled

May 2nd, 2022
985
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import sys
  4.  
  5. totalPrice = 0
  6. numberOfItems = 0
  7.  
  8. oldKey = None
  9.  
  10.  
  11. print ("{:<70} {:<20} {:<20}\n\n".format( "Winery Name","Total Revenue","Average Revenue"))
  12.  
  13. for line in sys.stdin:
  14.     data_mapped = line.strip().split("\t")
  15.     if len(data_mapped) != 2:
  16.         # Something has gone wrong. Skip this line.
  17.         continue
  18.  
  19.     thiskey, currentPrice = data_mapped
  20.  
  21.     if oldKey and oldKey != thiskey:
  22.         print ("{:<70} {:<20} {:<20}".format( oldKey,totalPrice,totalPrice/numberOfItems))
  23.         oldKey = thiskey;
  24.         totalPrice = 0
  25.         numberOfItems=0
  26.  
  27.  
  28.     oldKey = thiskey
  29.     numberOfItems+=1
  30.     totalPrice += float(currentPrice)
  31.  
  32.  
  33. if oldKey != None:
  34.     print ("{:<70} {:<20} {:<20}".format( oldKey,totalPrice,totalPrice/numberOfItems))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement