In Python Use the Design Recipe to write a function,  print_histogram  that consumes a list of numbers and prints a histogram graph using asterisks to represent each number in the list. Use one output line per number in the list. You may assume that only integers are passed to this function.  Your function should ignore negative values. Include a docstring!

Question
Asked Oct 24, 2019
138 views

In Python Use the Design Recipe to write a function,  print_histogram  that consumes a list of numbers and prints a histogram graph using asterisks to represent each number in the list. Use one output line per number in the list. You may assume that only integers are passed to this function.  Your function should ignore negative values. Include a docstring! 

check_circle

Expert Answer

Step 1

 

Programming Instructions:

 

  • Define the function print_histogram which takes the list of integers as an argument.
  • In the function, Use the for-loop to initialize the output and times each time.
  • In the loop, use anther loop which print the histogram if elements are greater than 0.
Step 2

def print_histogram( elements ):

    """

    Print the pattern(histogram) according to the elements in the list

    @type elements: list

    >>>print_histogram([2, 4, 6, 9, 5, 5, -2])

    **

    ****

    ******

    *********

    *****

    *****

    """

   

    for i in elements:    

        output = ' '  ...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Python

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: 1. What technique is used to model the situation that Student may have multiple addresses? A) Associ...

A: The answer is option B - Weak entitiesBecause the addresses belong to that student and cannot exist ...

question_answer

Q: Write a Java program that prompts the user for the page size used in a virtual memory system; this w...

A: A Java program that accepts a valid system page size and virtual address and calculates the page num...

question_answer

Q: Form boolean equations in POS and SOP forms from the truth table attached (PLEASE EXPLAIN ALL STEPS)...

A: The circuit diagrams that correspond to the following Boolean equations  drawed using an online tool...

question_answer

Q: Draw a flowchart for a program that shows the logic for a program that generates a random number.  T...

A: The following program will generate a random number 0 or 1. If the generated random number is 0, the...

question_answer

Q: m2 separated by a distance d is given by:F = Gm1m2d 2where G is the universal gravitational constant...

A: A C++  program to display the gravitational force between two objects is given below;Program code://...

question_answer

Q: The effects of lack of computer equipment in academic performance

A: To solve this problem .first of all you need to understand the relationship of computer devices in a...

question_answer

Q: I asked this question previously but the answer I got isn't really helping. I cant seem to get the p...

A: A Python program that uses a custom function to generate a specified number of random integers in a ...

question_answer

Q: Hey i need help with coding in c++  Q1 // with steps  Write a program that determines a student’s gr...

A: Approach for the program- 1)Import the essential headers.2)Define the main function.3)Declare the va...

question_answer

Q: Using MIPS assembly language can someone help me write a program that does .. Write a program to fin...

A: Program Instructions:Ask the user for number of integers and get those integers.Load the array, redu...