UMBC Bar Chart Function Project

Description

Write a function called ‘bar_chart’ based on the following IPO specification:

# function:   bar_chart# input:      x & y value (integers), labels, values and colors (lists)# processing: draws a bar chart with the origin of the chart being at the x#             and y value supplied. the height of the chart will always be#             100 units, and the width of each bar in the chart can be#             computed as 50 units for each value in the 'values' list.#             draw two black lines to show these axes.##             the height of each bar should be proportionally scaled so that#             no bar ever ends up having a height of over 100 units.  for example,#             with the list [100,200,300] the third bar would be 100 units#             high, the second would only be ~66 units high and the first would#             be ~33 units high (values can be rounded and don't need to be exact)#             #             each value in the 'labels' list indicates the label for each bar#             in the bar chart.  these should be written below the x-axis#             using the 'turtle.write' function.  Ensure that these labels are#             spaced out accordingly (50 pixels for each bar)#             #             each bar should be drawn on top of the x-axis with a height defined#             in the 'values' list.  the color for each bar can be extracted#             from the 'colors' list.  the value of each bar should also be #             written at the top of each bar.# output:     function returns no value

Here is a sample program and its desired output to test your work:

import turtleturtle.setup(600,600)bar_chart(-200,-200,["pikachu"], [99999], ['yellow'])bar_chart(0,-200,["x","y","hello","world"], [1000,900,800,700], ['grey','pink','black','purple'])bar_chart(-200,0,["apple", "pear", "orange"], [100,200,300], ['red', 'green', 'orange'])bar_chart(0,0,["a","b","c","d","e"], [50,70,90,10,30], ['blue','pink','red','green','yellow'])

Some hints:

  • You don’t need to validate your data – the function will always be called with the correct arguments with the correct data types
  • The items in each list are related to each other by position (i.e. in the first list “apple” has a value of 100 and a color of ‘red’)
  • Refer back to Assignment #6B and our lecture on turtle graphics if you need help getting started with turtle. You are welcome to use any functions that you wrote for that assignment, including the ‘generic_polygon’ function.

Get your college paper done by experts

Do my question How much will it cost?

Place an order in 3 easy steps. Takes less than 5 mins.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *