Appearance
question:Write a python function to calculate the total promotion cost for an animated film based on different distribution channels. Each channel has a unique cost per viewer. The function should take two lists as input: one list contains the number of viewers for each channel, and the other list contains the cost per viewer for the corresponding channels. The function should return the total promotion cost rounded to two decimal places.Input:- A list of integers, `viewers`, where each element represents the number of viewers reached through a specific distribution channel.- A list of floats, `cost_per_viewer`, where each element represents the cost per viewer for the corresponding channel in the `viewers` list.Output:- A float representing the total promotion cost, rounded to two decimal places.Example:```pythonviewers = [1000, 1500, 2000]cost_per_viewer = [0.5, 0.75, 1.2]```For the input above, the function should calculate the total cost as follows:- Channel 1: 1000 viewers * 0.5/viewer- Channel 2: 1500 viewers * 0.75/viewer- Channel 3: 2000 viewers * 1.2/viewerThe function should return the sum of these costs rounded to two decimal places.
answer:def calculate_promotion_cost(viewers, cost_per_viewer): total_cost = 0 for i in range(len(viewers)): total_cost += viewers[i] * cost_per_viewer[i] return round(total_cost, 2)
question:Write a python function to calculate the total calories burned during a workout session. The function should accept two inputs: a list of dictionaries containing details about each exercise performed, and a dictionary with the user's personal information, including age, weight, and gender. Each dictionary in the list represents an exercise and contains the exercise type, duration in minutes, and intensity level. The function should use the provided data to calculate the total calories burned based on standard metabolic rate formulas. Inputs:1. A list of dictionaries, where each dictionary represents an exercise and contains the keys: - 'type': a string representing the type of exercise (e.g., 'running', 'cycling') - 'duration': an integer representing the duration of the exercise in minutes - 'intensity': a string representing the intensity level of the exercise (e.g., 'low', 'medium', 'high')2. A dictionary representing the user's personal information with the keys: - 'age': an integer representing the user's age in years - 'weight': a float representing the user's weight in kilograms - 'gender': a string representing the user's gender ('male' or 'female')Output:- An integer representing the estimated total calories burned during the workout session.Example:```pythonexercises = [ {'type': 'running', 'duration': 30, 'intensity': 'high'}, {'type': 'cycling', 'duration': 45, 'intensity': 'medium'}]user_info = { 'age': 35, 'weight': 70.0, 'gender': 'female'}# The function call might look like this:total_calories = calculate_calories_burned(exercises, user_info)# Assuming the function is correctly implemented, it should return the total calories burned.print(total_calories) # Output: an estimated integer value based on the input data```
answer:def calculate_calories_burned(exercises, user_info): # Constants for MET values (Metabolic Equivalent of Task) MET_VALUES = { 'running': { 'low': 6.0, 'medium': 8.0, 'high': 10.0 }, 'cycling': { 'low': 4.0, 'medium': 6.0, 'high': 8.0 } } # Constants for BMR calculation BMR_MALE = 66.47 + (13.75 * user_info['weight']) + (5.003 * user_info['age']) - (6.755 * user_info['age']) BMR_FEMALE = 655.1 + (9.563 * user_info['weight']) + (1.85 * user_info['age']) - (4.676 * user_info['age']) # Calculate Basal Metabolic Rate (BMR) if user_info['gender'] == 'male': bmr = BMR_MALE else: bmr = BMR_FEMALE total_calories = 0 for exercise in exercises: exercise_type = exercise['type'] duration = exercise['duration'] intensity = exercise['intensity'] # Get the MET value for the given exercise and intensity met_value = MET_VALUES.get(exercise_type, {}).get(intensity, 0) # Calculate calories burned for the exercise calories_burned = (met_value * 3.5 * user_info['weight'] * duration) / 200 total_calories += calories_burned return int(total_calories)
question:Write a python function to determine if a given string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization). Your function should take a single string as input and return `True` if it's a palindrome, `False` otherwise.Input:- A single string containing letters, numbers, spaces, and/or punctuation.Output:- A boolean value: `True` if the input string is a palindrome, `False` otherwise.Example:```pythonis_palindrome("A man, a plan, a canal, Panama!") # should return Trueis_palindrome("Hello, World!") # should return False```
answer:def is_palindrome(s): # Remove non-alphanumeric characters and convert to lowercase cleaned_s = ''.join(char.lower() for char in s if char.isalnum()) # Check if the cleaned string is equal to its reverse return cleaned_s == cleaned_s[::-1]
question:Write a python function to analyze the growth of native plants in a restoration project. The function should take a list of integers as input, where each integer represents the growth in centimeters of a specific plant over a month. Your task is to return a dictionary with the following keys and their respective values:1. "total_growth": The total growth of all plants combined.2. "average_growth": The average monthly growth per plant, rounded to two decimal places.3. "max_growth": The maximum growth achieved by any single plant.4. "min_growth": The minimum growth recorded for any single plant.Input: A list of integers, e.g., `[5, 7, 3, 12, 9]`.Expected Output: A dictionary, e.g., `{"total_growth": 36, "average_growth": 7.20, "max_growth": 12, "min_growth": 3}`.Ensure that the function handles an empty list by returning a dictionary with all values set to zero.
answer:def analyze_plant_growth(growth_list): if not growth_list: return {"total_growth": 0, "average_growth": 0.0, "max_growth": 0, "min_growth": 0} total_growth = sum(growth_list) average_growth = round(total_growth / len(growth_list), 2) max_growth = max(growth_list) min_growth = min(growth_list) return { "total_growth": total_growth, "average_growth": average_growth, "max_growth": max_growth, "min_growth": min_growth }
question:Write a python function to calculate the average length of a list of film durations provided in minutes. The function should take a single input, which is a list of integers representing the duration of each film in minutes. The function should return a float representing the average duration of the films.Input:- A list of integers, where each integer is the duration of a film in minutes. The list can have 1 to 1000 elements, and each integer is between 1 and 300.Output:- A float representing the average duration of the films.Example:```pythonfilm_durations = [120, 90, 115, 130]average_duration = calculate_average_duration(film_durations)print(average_duration) # Output should be 113.75```Note: If the input list is empty, the function should return 0.0.
answer:def calculate_average_duration(film_durations): if not film_durations: return 0.0 total_duration = sum(film_durations) num_films = len(film_durations) average_duration = total_duration / num_films return average_duration
question:Write a python function to calculate the total number of words in a given list of sentences, excluding any occurrences of a specific word. The function should take two inputs: a list of strings (each string representing a sentence) and a string representing the word to exclude. The output should be an integer representing the total word count after excluding the specified word.Input:- `sentences`: A list of strings, e.g., `["The quick brown fox", "jumps over the lazy dog", "The quick brown fox again"]`.- `exclude_word`: A string, e.g., `"the"`.Expected Output:- An integer representing the total count of words, excluding the specified word.Example:```pythonsentences = ["The quick brown fox", "jumps over the lazy dog", "The quick brown fox again"]exclude_word = "the"# Expected output would be 10 because the word "the" is excluded from the count.```Please provide a solution that efficiently handles the word exclusion and calculates the total word count.
answer:def count_words_excluding(sentences, exclude_word): total_count = 0 for sentence in sentences: words = sentence.split() for word in words: if word.lower() != exclude_word.lower(): total_count += 1 return total_count