Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. # BarGraphify(nums) takes a list of non-negative integers and prints a set of horizontal bars.
  2.  
  3. print "III. BarGraphify(nums) \n"
  4.  
  5. def BarMaker(nums): # Helper function
  6.     output = "" # Gets returned
  7.     while nums != 0: # Runs while nums isn`t 0
  8.         nums -= 1 # Continually decreases nums by 1 until it gets to 0.
  9.         output += "=" # Makes the horizontal bars
  10.         if nums == 0:
  11.             return output
  12.  
  13. def BarGraphify(nums):
  14.     for num in nums: # For all the elements in list nums
  15.         print BarMaker(num)
  16.  
  17. print BarGraphify( [0,1,2,3] )
  18. print " ^ It should be = == ===. \n"
  19.  
  20. print BarGraphify( [1,0,3,2] )
  21. print " ^ It should be =  === ==. \n"
  22.  
  23. print BarGraphify( [5,6,4,3,1] )
  24. print " ^ It should be ===== ====== ==== === =. \n"
  25.  
  26. print BarGraphify( [1,1,1,1,1] )
  27. print " ^ It should be = = = = =."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement