Appearance
question:Write a python function to help manage and organize a list of bioethics committee meetings. The function should take a list of dictionaries, where each dictionary represents a meeting with the following keys: 'date' (a string in the format 'YYYY-MM-DD'), 'topic' (a string describing the topic of the meeting), and 'duration' (an integer representing the duration of the meeting in minutes). The function should return a list of meeting topics sorted by the meeting date in ascending order. For example, given the input:```python[ {'date': '2023-07-15', 'topic': 'Genetic Privacy', 'duration': 90}, {'date': '2023-05-01', 'topic': 'AI in Healthcare', 'duration': 60}, {'date': '2023-06-21', 'topic': 'End-of-Life Decisions', 'duration': 120}]```The expected output should be:```python['AI in Healthcare', 'End-of-Life Decisions', 'Genetic Privacy']```Please ensure that the function handles an empty list gracefully, returning an empty list in such cases.
answer:def organize_meetings(meetings): if not meetings: return [] sorted_meetings = sorted(meetings, key=lambda x: x['date']) sorted_topics = [meeting['topic'] for meeting in sorted_meetings] return sorted_topics
question:Write a python function to determine the total energy consumption of an electric vehicle over a given distance. The function should take in three parameters: the distance traveled in kilometers (an integer), the energy consumption rate in kWh per 100 kilometers (a float), and an optional parameter representing the efficiency improvement percentage (a float, default is 0). The function should return the total energy consumed in kWh as a float, considering any efficiency improvement.For example, if the distance traveled is 150 kilometers, the energy consumption rate is 15 kWh/100 km, and the efficiency improvement is 10%, the function should calculate the reduced energy consumption rate and then determine the total energy consumed over the given distance.
answer:def calculate_energy_consumption(distance, consumption_rate, efficiency_improvement=0): # Calculate the reduced energy consumption rate considering efficiency improvement reduced_consumption_rate = consumption_rate * (1 - efficiency_improvement / 100) # Calculate the total energy consumed based on distance and reduced consumption rate total_energy_consumed = (distance / 100) * reduced_consumption_rate return total_energy_consumed
question:Write a python function to determine if a given street name in Middleburg is considered a "main street" based on a predefined list of main streets. The function should take a single string input representing the street name and return a boolean value indicating whether it is a main street or not.Input:- A string `street_name` representing the name of the street.Output:- A boolean value `True` if the street is a main street, `False` otherwise.Assume we have a list of main streets in Middleburg as follows:```pythonmain_streets = ["Main Street", "Broadway", "Elm Street", "Maple Avenue", "Pine Lane"]```Example:```pythonis_main_street("Main Street") # Should return Trueis_main_street("Oak Street") # Should return False```This function will help us identify the key streets in our beloved town of Middleburg.
answer:def is_main_street(street_name): main_streets = ["Main Street", "Broadway", "Elm Street", "Maple Avenue", "Pine Lane"] return street_name in main_streets
question:Write a python function to calculate the apparent brightness of a star from its absolute magnitude and distance from Earth. The function should take two arguments: the absolute magnitude of the star (a float) and the distance to the star in light-years (a float). It should return the apparent magnitude (a float).The formula to convert absolute magnitude (M) and distance (d) to apparent magnitude (m) is:[ m = M + 5 times (log_{10}(d) - 1) ]Input:- `absolute_magnitude`: A float representing the absolute magnitude of the star.- `distance`: A float representing the distance to the star in light-years.Output:- A float representing the apparent magnitude of the star.Example:If the absolute magnitude of a star is 5.0 and it is 10 light-years away, the function should return approximately 7.5.
answer:def calculate_apparent_magnitude(absolute_magnitude, distance): import math apparent_magnitude = absolute_magnitude + 5 * (math.log10(distance) - 1) return apparent_magnitude
question:Write a python function to calculate the average score of students from a list of scores, but exclude the lowest score from the calculation. This is intended to help better understand the overall performance without one potentially anomalous low score skewing the results. Input: A list of integers representing student scores. The list will contain at least two scores.Output: A float representing the average score after removing the lowest score.Example: If the input list is `[70, 85, 90, 60, 80]`, the function should remove the lowest score `60` and calculate the average of `[70, 85, 90, 80]`, which results in `81.25`.
answer:def calculate_average_without_lowest(scores): if len(scores) < 2: return None lowest_score = min(scores) filtered_scores = [score for score in scores if score != lowest_score] average = sum(filtered_scores) / len(filtered_scores) return average
question:Write a python function to calculate the total cost of a customer's purchase at The Sweet Spot, including a loyalty discount. The function should take two inputs: a list of tuples where each tuple represents an item and its price (e.g., `[('chocolate', 2.5), ('candy', 1.0)]`) and a loyalty discount percentage as a float (e.g., `10` for 10%). The function should return the total cost after applying the discount.Input:- A list of tuples, where each tuple contains a string (item name) and a float (item price).- A float representing the loyalty discount percentage.Output:- A float representing the total cost after applying the discount.Example:```pythonitems = [('chocolate', 2.5), ('candy', 1.0), ('cookie', 1.5)]discount_percentage = 10# Expected output: 4.95```
answer:def calculate_total_cost(items, discount_percentage): total_cost = sum(item_price for item_name, item_price in items) discount = total_cost * (discount_percentage / 100) discounted_total_cost = total_cost - discount return discounted_total_cost