Programming with Python

⌘K
  1. Home
  2. Docs
  3. Programming with Python
  4. List, Tuples and Dictiona...
  5. Illustrative Problems &#8...
  6. Histogram

Histogram

A histogram is a graphical representation that organizes a group of data points

Program

def hist_gram(a):
	for i in a:
		sum = " "
		while(i > 0):
			sum = sum + "$"
			i = i - 1
		print(sum)

n = int(input("Enter number of elements:"))
list1=[]
print("Enter elements:")
for i in range(0,n):
	list1.append(int(input()))
hist_gram(list1)

Output

Enter number of elements:4
Enter elements:
1
2
3
4
 $
 $$
 $$$
 $$$$

Views: 0

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments