Appearance
question:Write a python function to calculate the future value of an investment using the principles of Islamic banking, which does not allow for interest (riba) but instead uses profit-sharing agreements. The function should take as input the initial investment amount, a list of projected yearly profit rates (as percentages), and the number of years the investment will be held. The function should return the future value of the investment after the specified number of years, assuming profits are reinvested each year. Inputs:- initial_investment: A float representing the initial amount of money invested.- profit_rates: A list of floats representing the yearly profit rates as percentages.- years: An integer representing the number of years the investment will be held.Output:- A float representing the future value of the investment.Example:```pythoninitial_investment = 1000.0profit_rates = [5.0, 6.0, 4.5] # in percentagesyears = 3# Expected output: 1159.17 (calculated as 1000 * 1.05 * 1.06 * 1.045)```
answer:def calculate_future_value(initial_investment, profit_rates, years): future_value = initial_investment for i in range(years): profit_rate = profit_rates[i] / 100 future_value *= (1 + profit_rate) return future_value
question:Write a python function to determine the total elevation gain for a given hiking trail based on a list of elevation data points. Each data point represents the elevation (in meters) at a specific location along the trail. The function should calculate the total amount of elevation gained over the course of the hike. If the elevation decreases at any point, it should not be subtracted from the total gain. Input:- A list of integers where each integer represents the elevation at a specific point along the trail.Output:- An integer representing the total elevation gain.Example:```Input: [100, 150, 200, 180, 220, 300]Output: 220```In the example, the hiker gains 50 meters from 100 to 150, another 50 meters from 150 to 200, and then 20 meters from 200 to 220, and finally 80 meters from 220 to 300, totaling 220 meters of elevation gain. The descent from 200 to 180 is ignored.
answer:def calculate_elevation_gain(elevation_data): total_gain = 0 previous_elevation = elevation_data[0] for current_elevation in elevation_data[1:]: if current_elevation > previous_elevation: total_gain += current_elevation - previous_elevation previous_elevation = current_elevation return total_gain
question:Write a python function to calculate the total profit from a list of daily profit percentages for a given investment. The function should take two inputs: an initial investment amount (a positive float or integer) and a list of daily profit percentages (a list of integers or floats). The output should be a float representing the final amount of money after applying the daily profit percentages consecutively on the initial investment.Assume the daily profit is given in percentages, and each day's profit should be added to the investment before applying the next day's percentage. For example, if the initial investment is 100 and the daily profits are [10, -5, 20], the calculation should be:1. Day 1: 100 + 10% = 1102. Day 2: 110 - 5% = 104.53. Day 3: 104.5 + 20% = 125.4The function should return 125.4 in this case.Input:- initial_investment: float or int, e.g., 100- daily_profits: list of floats or ints, e.g., [10, -5, 20]Output:- float, representing the final amount, e.g., 125.4Make sure to handle an empty list of daily profits by returning the initial investment amount.
answer:def calculate_total_profit(initial_investment, daily_profits): total_amount = initial_investment for profit in daily_profits: total_amount += total_amount * (profit / 100) return total_amount
question:Write a python function to analyze a list of historical political events in the Philippines and count the number of events that occurred within a specified year range. The function should be named `count_events_in_year_range` and take three parameters: a list of tuples where each tuple contains a string (the event description) and an integer (the year the event took place), an integer `start_year`, and an integer `end_year`. The function should return the count of events that took place between `start_year` and `end_year`, inclusive.Input:- A list of tuples `events`, where each tuple is of the form `(event_description: str, event_year: int)`.- An integer `start_year` representing the start of the year range.- An integer `end_year` representing the end of the year range.Output:- An integer representing the number of events that occurred between `start_year` and `end_year`, inclusive.Example:```pythonevents = [ ("EDSA People Power Revolution", 1986), ("Second EDSA Revolution", 2001), ("Makati Siege", 1989), ("Declaration of Martial Law", 1972), ("Philippine Independence", 1946)]count = count_events_in_year_range(events, 1980, 2000)print(count) # Output should be 2```
answer:def count_events_in_year_range(events, start_year, end_year): count = 0 for event_description, event_year in events: if start_year <= event_year <= end_year: count += 1 return count
question:Write a python function to calculate the daily milk production from a list of milk yields for a week. As a retired dairy farmer, I have a list where each element represents the total milk production in gallons for a specific day of the week, starting with Monday and ending with Sunday. The function should take this list as input and return a dictionary where the keys are the days of the week and the values are the corresponding milk production for each day.Input:- A list of 7 integers, each representing the milk production in gallons for a day, starting from Monday to Sunday.Output:- A dictionary with the days of the week as keys and the daily milk production as values.Example:```python# Example inputmilk_yields = [150, 160, 145, 155, 148, 160, 152]# Expected output# {# "Monday": 150,# "Tuesday": 160,# "Wednesday": 145,# "Thursday": 155,# "Friday": 148,# "Saturday": 160,# "Sunday": 152# }```I would appreciate any guidance or sample code to accomplish this task. Thank you!
answer:Here's the Python function to calculate the daily milk production from a list of milk yields for a week:```pythondef calculate_daily_milk_production(milk_yields): days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] daily_production = {} for i in range(len(milk_yields)): daily_production[days[i]] = milk_yields[i] return daily_production```This function takes a list `milk_yields` as input, where each element represents the milk production in gallons for a specific day of the week, starting from Monday.Here's how it works:1. We define a list `days` containing the names of the days of the week in order.2. We create an empty dictionary `daily_production` to store the daily milk production.3. We iterate over the `milk_yields` list using a `for` loop with the index `i`.4. For each iteration, we use the index `i` to access the corresponding day from the `days` list and the milk yield from the `milk_yields` list.5. We store the milk yield as the value in the `daily_production` dictionary, with the corresponding day as the key.6. Finally, we return the `daily_production` dictionary.Example usage:```pythonmilk_yields = [150, 160, 145, 155, 148, 160, 152]daily_production = calculate_daily_milk_production(milk_yields)print(daily_production)```Output:```{ 'Monday': 150, 'Tuesday': 160, 'Wednesday': 145, 'Thursday': 155, 'Friday': 148, 'Saturday': 160, 'Sunday': 152}```
question:Write a python function to analyze a list of strings, where each string represents a news article headline. The function should identify and return the headlines that contain any words from a predefined list of "sensitive words," which are related to violence. The input to the function will be two arguments: a list of strings `headlines` and a list of strings `sensitive_words`. The output should be a list of strings that are the headlines containing any of the sensitive words.For example, given the following input:```pythonheadlines = [ "Local community rallies for peace", "Violence erupts in downtown area", "Charity event raises funds for victims", "New policy aims to reduce crime"]sensitive_words = ["violence", "crime", "victims"]```The expected output would be:```python["Violence erupts in downtown area", "Charity event raises funds for victims", "New policy aims to reduce crime"]```I feel deeply for those affected and would appreciate guidance on how to create a function that can help in identifying such headlines. Thank you for your support and understanding.
answer:def analyze_headlines(headlines, sensitive_words): sensitive_headlines = [] for headline in headlines: headline_words = headline.lower().split() for word in sensitive_words: if word in headline_words: sensitive_headlines.append(headline) break return sensitive_headlines