1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
AURORKA [14]
3 years ago
9

Implement a function with signature barGraph(w, h, data) which creates and returns a cs1graphics.Canvas instance that has width

w and height h and which visualizes the given data as a bar graph. The data will be a nonempty list of positive integers. (You do not need to error-check the parameters.) Your visualization must have rectanglar bars with equal width that collectively use 80% of the width of the canvas (leaving 10% padding on left and right) and the bars should be vertically aligned at their bottom edge such that the maximum value in the data results in a bar that uses 80% of the height of the canvas (leaving 10% padding at top and bottom). As an example, the call barGraph (400, 300, [5, 8, 2, 7]) should produce the following image: from cs1graphics import * def barGraph(w, h, data): pass
Computers and Technology
1 answer:
arsen [322]3 years ago
6 0

Answer:

def barGraph(w, h, data):

  # creating Canvas

  paper = Canvas(w, h)

  # defining variables

  largest = max(data) # largest element in data

  length = len(data) # length of data list

  barWidth = 0.8 * w / length # length of each bar of the histogram

  maxBarHeight = 0.8 * h # maximum height of each bar of the histogram

  minBarHeight = maxBarHeight / largest # minimum height of each bar

  # Starting points

  x = 0.1 * w

  y = 0.9 * h

  # looping through the list

  for i in data:

      currBarHeight = minBarHeight * i # current bar height

      x1 = x + barWidth

      y1 = y - currBarHeight

      # creating the rectangle, and adding it to the bar graph

      bar = Polygon( Point(x,y), Point(x,y1), Point(x1,y1), Point(x1,y) )

      bar.setFillColor('grey')

      paper.add(bar)

      x = x1

  # returning the canvas

  return paper

You might be interested in
WHAT IS THE LOCATION OF “A”. ON THE GRID?
satela [25.4K]

Answer:

The location of A on the grid is (-200, 100).

Explanation:

Because A is left of the origin 200 units, the x-coordinate will be negative 200. Also, A is above the origin 100 units, so the y-coordinate will be positive 100. Therefore, the answer is C, or (-200, 100).

7 0
3 years ago
Read 2 more answers
<img src="https://tex.z-dn.net/?f=1%20%5Ctimes%202" id="TexFormula1" title="1 \times 2" alt="1 \times 2" align="absmiddle" class
Ber [7]
The answer is 2, but this is something you should know
8 0
3 years ago
Read 2 more answers
You want to change your cell phone plan and call the company to discuss options
Vikki [24]
And? What’s the point? The question?
3 0
3 years ago
________ was the communication medium of choice for early computer criminals.
vladimir1956 [14]
I would say that morse code would be the answer, but im not sure if that would apply to  computers
5 0
4 years ago
Galleons, Sickles, and Knuts are types of coinage from the Harry Potter franchise. Write source code in C++ that converts the nu
olga2289 [7]

Answer:

The c++ program for the given scenario is given below.

#include <iostream>

using namespace std;

int main() {

   double galleons, knuts;    

   cout << " This program converts Galleons to Knuts " << endl;

   cout << " Enter the number of galleons to be converted into knuts: " << endl;

   cin >> galleons;    

   knuts = galleons * 493;    

   cout << galleons << " Galleons is equivalent to " << knuts << " Knuts. " << endl;

   return 0;

}

OUTPUT

For decimal value.

This program converts Galleons to Knuts  

Enter the number of galleons to be converted into knuts:  

1.1

1.1 Galleons is equivalent to 542.3 Knuts.  

For integer value.

This program converts Galleons to Knuts  

Enter the number of galleons to be converted into knuts:  

2

2 Galleons is equivalent to 986 Knuts.

Explanation:

This program uses two variables to holds galleons and knuts which are declared with data type double.

 double galleons, knuts;

The data type double is taken since it can hold both integer and decimal values.

The variables are not initialized since the program is supposed to take user input for the number of galleons to be converted to knuts as shown below.

The cout keyword is used to print to the standard output.

 cout << " Enter the number of galleons to be converted into knuts: " << endl;

The cin keyword is used to take the input from the user.

 cin >> galleons;

Galleons are converted into knuts using the conversion rate given in the question. The formula to convert galleons into knuts is given as follows.

  knuts = galleons * 493;

The entered number of galleons and the corresponding number of knuts are displayed to the standard output.

  cout << galleons << " Galleons is equivalent to " << knuts << " Knuts. " << endl;

In the program, endl keyword is used to insert new line.

The program terminates with the following statement since the return type of main is shown as integer.

 return 0;

4 0
4 years ago
Other questions:
  • After applying transitions to his presentation, Omar uses the Slide Show feature to view the them. He notices that the transitio
    9·2 answers
  • What can you say about the following Java class definition?
    10·1 answer
  • Write a program that reads three numbers and print the largest one step by step answer
    9·1 answer
  • Why was unicode invented?
    10·1 answer
  • Ronald downloads a movie from the Internet onto his company's computer. During this process, his system gets infected with a vir
    12·1 answer
  • p25: File Write and Read1) User enters a file name (such as "myMovies.txt").2) User enters the titles of 4 of their favorite mov
    12·1 answer
  • A vending machine that serves coffee pours a varying
    10·1 answer
  • Which of the following terms means the computer operating system automatically detects and installs the proper driver for a new
    9·1 answer
  • All Office programs have similar commands on the tab for changing the document view a. File b. View c. Locate d. display ​
    5·1 answer
  • Which organization provides a free, online html5 validator application to ensure that a webpage's html tags follow the rules for
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!