Question

Problem 20 [ 2 points ] Use the Design Recipe to write a function, print_histogram that...

Problem 20 [ 2 points ]

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!

Test
Result
print_histogram([ 0, 2, 4, 1])
**
****
*
print_histogram([10, 5, 3, -1, 8])
**********
*****
***
********

-------------------------------------------------------------------------

Part 2

Use the Design Recipe to write a function, count_odds, that consumes a list and two integers, lower_bound and upper_bound, and returns the number of all the odd integers in the list that are between lower_bound and upper_bound (inclusive of both lower_bound and upper_bound). Include a docstring!

For example:

Test
Result
print(count_odds([0, 100, 50, 20], 10, 60))
  0
print(count_odds([1, 100, 85, 63, 52, 60, 50], 50, 100))
  2
print(count_odds([-17, -20, -33, 41, 19, 61], -17, 61))
  4


0 0
Add a comment Improve this question Transcribed image text
Answer #1
Answer:
def print_histogram(lst):
    for x in lst:
        if(x>0):
            print("*"*x)

###############################

def count_odds(lst, lower_bound, upper_bound):
    count = 0
    for x in lst:
        if (x>=lower_bound) and (x<=upper_bound):
            if(x%2==1):
                count += 1
    return count
Add a comment
Know the answer?
Add Answer to:
Problem 20 [ 2 points ] Use the Design Recipe to write a function, print_histogram that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python Use the Design Recipe to write a function called running_average that repeatedly asks the user...

    Python Use the Design Recipe to write a function called running_average that repeatedly asks the user to input integers at the keyboard until they type the word done. Return the average of the values they entered. You may assume the user will only enter integers or "done". Include a docstring!

  • Python Language The Blip Blob New Year celebration started on a Tuesday. Use the Design Recipe...

    Python Language The Blip Blob New Year celebration started on a Tuesday. Use the Design Recipe to write a function called blip_blop_day that consumes an int representing the number of days that have passed since their celebration start day and returns name of the current day. For example, if 2 days have passed, then 'Thursday' should be returned. Include a docstring! For example: Test Result 2 Thursday 4 Saturday Monday Tuesday 6 7 8 Wednesday

  • PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a...

    PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a function yesOrNo which has no parameters. When called, it gets input from the user until the user types either 'yes' or 'no', at which point the function should return True if the user typed 'yes' and False if the user typed 'no'. Any other entries by the user are ignored and another value must be input. For example: Test Input Result print(yesOrNo()) hello blank...

  • Python Language ! Use the Design Recipe to define a function save_history which consumes two parameters,...

    Python Language ! Use the Design Recipe to define a function save_history which consumes two parameters, a nested list and an int representing the current landing attempt. The function should open a new file named LandingNN.csv' where NN is two digits representing the current landing attempt. The first line should contain the number of sublists in the nested list. Each sublists should be written to the file on its own line with its values separated by commas. This function should...

  • In this problem, you should write one function named copy and increment. This function will have...

    In this problem, you should write one function named copy and increment. This function will have one parameter, which you can assume will be a list of integers. This function should return a copy of the parameter list, in which each number from the parameter list has been increased by 1. The function should not modify the values in the parameter list. For example, the code: values - 20, 40, 10, 60, 77, 2) other copy and incrementales) print values...

  • 0% of final (S1 2019) Write a function called sum_of_products(x), where x is a list of lists of i...

    0% of final (S1 2019) Write a function called sum_of_products(x), where x is a list of lists of integers, this function returns a number which is the sum of the products of each list of integers. For example: print(sum_of_products ([[1,2], [5], [2,5]])) will result in the output: 17 That is, the result of 2 + 5+ 10 For example: Test Result print(sum_of_products( [2,3]])) print sum_of_products([[2],[3]])) print(sum_of_products([[1,21,[S],[2,5]1)) 17 0% of final (S1 2019) Write a function called sum_of_products(x), where x is...

  • Write a python program (recursive.py) that contains a main() function. The main() should test the following...

    Write a python program (recursive.py) that contains a main() function. The main() should test the following functions by calling each one with several different values. Here are the functions: 1) rprint - Recursive Printing: Design a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. 2) rmult - Recursive Multiplication: Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times...

  • Use the FDR to design and write a function, maxValTimes, that takes a list of integers...

    Use the FDR to design and write a function, maxValTimes, that takes a list of integers and returns a set containing the value(s) that occur the same number of times as the maximum value in the list. If the list is empty, return an empty set.   For example if the list was [2,1,1,2,3,3,1] the function would return {2,3} as the maximum value is 3 which occurs twice, and 2 also occurs twice (but 1 occurs 3 times). For full marks,...

  • ****python**** Q1. Write a recursive function that returns the sum of all numbers up to and...

    ****python**** Q1. Write a recursive function that returns the sum of all numbers up to and including the given value. This function has to be recursive; you may not use loops! For example: Test Result print('%d : %d' % (5, sum_up_to(5))) 5 : 15 Q2, Write a recursive function that counts the number of odd integers in a given list. This function has to be recursive; you may not use loops! For example: Test Result print('%s : %d' % ([2,...

  • BlockPy: #33.8) Maximum Odd Use the Min/Max pattern to write a function maximum_odd that finds the...

    BlockPy: #33.8) Maximum Odd Use the Min/Max pattern to write a function maximum_odd that finds the highest odd value in the list (consumes a list of numbers and returns a number). Use the provided helper function is_odd (that consumes a single number and returns a boolean indicating whether it is true or false). Do not change the helper function is odd. Call your maximum_odd function on your favorite list of numbers Console Feedback: Instructor Feedback You cannot use the builtin...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT