In: Computer Science
Consider an image with coins of various sizes spread on a uniform background. Assume the coins DO touch each other and write a pseudo code to plot a histogram of the area of the coin (along the x-axis) vs the number of coins for a given area (along the y-axis). Write a python program to accomplish the same. If only a few coins overlap, determine the approximate number of coins.
# PLEASE LIKE THE SOLUTION
# FEEL FREE TO DISCUSS IN COMMENT SECTION
# PYTHON PROGRAM
import math
from matplotlib import pyplot as plt
import numpy as np
# main method
def main():
# now read the total area
area = float(input("Enter the total area "))
coinN =[]
coinAreaList = []
for carea in range (1,11):
# now start from the coin area
1
radius =math.sqrt((carea/3.14))
diameter = 2*radius
# area covered by coin
coinArea = diameter*diameter
# number of coin = total Area /
each coin area
n =
math.ceil((area/coinArea))
coinAreaList.append(carea)
coinN.append(n)
# bar
plt.bar(coinAreaList,coinN,tick_label =
coinAreaList,width = 0.8, color = ['red'])
# x
plt.xlabel('coin area')
# y
plt.ylabel('number of coins')
# pot
plt.show()
# PROGRAM EXECUTION STARTS HERE
main()
# SAMPLE OUTPUT