histogram()
that takes a list of integers and prints a histogram to the screen. For example, histogram([4, 9, 7])
should print the following:****
*********
*******
class Solution:
def hist1(self,vector):
a1=[0]*len(vector)
for i in range(len(vector)):
a1[i]='*'*vector[i]
for j in range(len(a1)):
print(a1[j])
kk=Solution()
if __name__=="__main__":
kk.hist1([2,5,8])
results:
No comments:
Post a Comment