Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # BarGraphify(nums) takes a list of non-negative integers and prints a set of horizontal bars.
- print "III. BarGraphify(nums) \n"
- def BarMaker(nums): # Helper function
- output = "" # Gets returned
- while nums != 0: # Runs while nums isn`t 0
- nums -= 1 # Continually decreases nums by 1 until it gets to 0.
- output += "=" # Makes the horizontal bars
- if nums == 0:
- return output
- def BarGraphify(nums):
- for num in nums: # For all the elements in list nums
- print BarMaker(num)
- print BarGraphify( [0,1,2,3] )
- print " ^ It should be = == ===. \n"
- print BarGraphify( [1,0,3,2] )
- print " ^ It should be = === ==. \n"
- print BarGraphify( [5,6,4,3,1] )
- print " ^ It should be ===== ====== ==== === =. \n"
- print BarGraphify( [1,1,1,1,1] )
- print " ^ It should be = = = = =."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement