Write a function called get_median that accepts a list of numbers and returns the median value of
Question:
Write a function called get_median that accepts a list of numbers and returns the median value of the list. The median value is the middle value in an ordered sequence of numbers. If there are two values in the middle (a, and b), then the median is the value halfway between them (e.g., (a + b) / 2. The list passed as a parameter should not be altered. If the list contains any negative numbers then generate a ValueError exception with the message "Negative numbers are invalid"
For example:
Test | Result |
---|---|
print(get_median([5, 1, 4, 2, 3])) | 3 |
and
A Person class should store the name and phone number for a person.
The following code shows how the Person class is used:
name = 'Ann' phone = 67362123 p = Person(name, phone) p.update_phone(123456) print(p)
This code would produce the output:
Contact Ann at 123456
Write the constructor, the update_phone method, and the __str__ method for the Person class. Submit the entire class.
and
Given a dictionary representing a frequency table of words, write a function called get_ordered_words that will accept the dictionary as a parameter and return a list of the words, ordered by the number of times they appeared (most frequent first), and then alphabetically if they appeared the same number of times.
For example:
Test | Result |
---|---|
freq = {'e': 2, 'c': 3, 'a': 2, 'b': 3, 'd': 2, 'f': 1} print(get_ordered_words(freq)) | ['b', 'c', 'a', 'd', 'e', 'f'] |
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp