In this assignment you will implement a library of functions that can be used to draw a histogram (bar graph) in ASCII art style. Your library will create a list of strings that, when printed appropriately, form a histogram of a list of data points, and is made of a given character. For example, if every element of the list *[3, 2, 4]* using the string character # is printed, this would be the result:
###
##
####
The returned list for this histogram should look like this:
["### ", "## ", "####"]
Notice that the strings in this list are padded by space characters on the right so that all the strings will be of equal length. This length is determined by the greatest value in the list to be plotted. In the example above, the length of the strings in the list is 4. When this histogram is flipped horizontally and printed `element by element,` the following results: ### ## #### The *returned list* for this histogram should look like this:
[" ###", " ##", "####"]
Design, implement, and test a program that satisfies the requirements below.
Requirements¶
Implement makeRow(w,m,c) which returns the rows for the unflipped histogram by doing the following:
Implement histogram(a,c) which returns the unflipped histogram by doing the following:
Implement flipHist(a,c) which returns the flipped histogram by doing the following:
The program requires very little besides the function definitions. There is no main().
Python programming language
Code:
def makeRow(w,m,c):
a=str(c)*w+ (" ")*(m-w)
return a
def histogram(a,c):
m=max(a)
for i in range(len(a)):
a[i]=makeRow(a[i],m,c)
return a
def flipHist(a,c):
m=max(a)
a=histogram(a,c)
l=[]
for i in range(m-1,-1,-1):
s=""
for j in
range(len(a)):
s=s+a[j][i]
l.append(s)
return l
a=[12,3,4,10,5,9]
l=[]
l=flipHist(a,'#')
for i in l:
print(i)
-------------
Code photo with sample output:
Explanation:
The makeRow function returns the string of length m with w chracters c and remaining spaces.
This is used by histogram function to create unflipped histogram. Note that m=max(a) gives the maximum element in a.
The fliphist function chooses the last index from each string of list a returned by histogram function.
This strings are stored in list L.
The strings of l can be printed to produce histogram.
----
Please upvote the answer if it works for you. Any feedback would be greatly appreciated.
<<<<<<<<<<<<<<python code>>>>>>>>>>>>>>>>>>>
def makeRow(w,m,c):
string=m*c
return string.ljust(w)
def ℎ????????(?,?):
unflipped=[]
for i in a:
unflipped.append(makeRow(max(a),i,c))
return unflipped
def ????????(?,?):
list1=ℎ????????(?,?)
for i in list1:
print(i)
????????([1,6,5,4,7,8,9,10],'*')
>>>>>>>>>>>>>>>>screen shot<<<<<<<<<<<<<<<<<<

In this assignment you will implement a library of functions that can be used to draw...