Skip to content
🤔 AI effective tips collection 🧠
question:Write a python function to calculate the daily caloric intake needed for an individual in addiction recovery, based on their age, weight, height, gender, and activity level. The function should take the following inputs:- age: An integer representing the age in years.- weight: A float representing the weight in kilograms.- height: A float representing the height in centimeters.- gender: A string that can either be "male" or "female".- activity_level: A string that can be one of the following: "sedentary", "lightly active", "moderately active", "very active", or "super active".The function should return an integer representing the estimated daily caloric intake. The calculation should use the Mifflin-St Jeor Equation to estimate the Basal Metabolic Rate (BMR) and then adjust for activity level with the following multipliers:- Sedentary (little or no exercise): BMR * 1.2- Lightly active (light exercise/sports 1-3 days/week): BMR * 1.375- Moderately active (moderate exercise/sports 3-5 days/week): BMR * 1.55- Very active (hard exercise/sports 6-7 days a week): BMR * 1.725- Super active (very hard exercise, physical job, or training twice a day): BMR * 1.9Example:Input: age=30, weight=70.0, height=175.0, gender="male", activity_level="moderately active"Output: 2731Note: The Mifflin-St Jeor Equation is as follows:- For males: BMR = (10 * weight) + (6.25 * height) - (5 * age) + 5- For females: BMR = (10 * weight) + (6.25 * height) - (5 * age) - 161

answer:def calculate_daily_caloric_intake(age, weight, height, gender, activity_level): # Calculate BMR using Mifflin-St Jeor Equation if gender == "male": bmr = (10 * weight) + (6.25 * height) - (5 * age) + 5 else: bmr = (10 * weight) + (6.25 * height) - (5 * age) - 161 # Adjust for activity level if activity_level == "sedentary": daily_caloric_intake = bmr * 1.2 elif activity_level == "lightly active": daily_caloric_intake = bmr * 1.375 elif activity_level == "moderately active": daily_caloric_intake = bmr * 1.55 elif activity_level == "very active": daily_caloric_intake = bmr * 1.725 else: # "super active" daily_caloric_intake = bmr * 1.9 return int(daily_caloric_intake)

question:Write a python function to calculate the average word length in a given sentence. The function should take a single string input, which represents a sentence consisting of words separated by spaces. It should return a float representing the average word length, rounded to two decimal places.Input:- A string `sentence` containing words separated by spaces. The sentence will not contain any punctuation and will have at least one word.Output:- A float representing the average length of the words in the sentence, rounded to two decimal places.Example:```pythonsentence = "The quick brown fox jumps over the lazy dog"# The function should return 3.89 since the total length of words is 35 and there are 9 words.```

answer:def calculate_average_word_length(sentence): words = sentence.split() total_length = sum(len(word) for word in words) num_words = len(words) average_length = total_length / num_words return round(average_length, 2)

question:Write a python function to calculate the number of stars visible in the night sky based on the cultural significance of constellations in my rural area. In my culture, certain constellations are associated with specific times of the year, and each has a different number of stars that are considered significant.The function should take two inputs:1. A list of tuples, where each tuple contains the name of a constellation and the number of stars in it (e.g., `[('Orion', 7), ('Pleiades', 6)]`).2. A list of constellation names that are visible during the current month (e.g., `['Orion', 'Pleiades']`).The function should return the total number of significant stars visible in the current month.Example:```pythonconstellations = [('Orion', 7), ('Pleiades', 6), ('Ursa Major', 5)]visible_constellations = ['Orion', 'Pleiades']# The function should return 13 because Orion has 7 stars and Pleiades has 6 stars.```Please make sure to handle the case where a constellation in the visible list may not be in the constellation data.

answer:def calculate_visible_stars(constellation_data, visible_constellations): total_stars = 0 for constellation, num_stars in constellation_data: if constellation in visible_constellations: total_stars += num_stars return total_stars

question:Write a python function to calculate the average number of goals scored per match for each player in a given list. The function should take a list of dictionaries as input, where each dictionary represents a player's performance. Each dictionary contains the player's name as a string, the number of goals they scored as an integer, and the number of matches they played as an integer. The function should return a dictionary where the keys are player names and the values are their average goals per match, rounded to two decimal places.Example:Input:```python[ {"name": "Player A", "goals": 10, "matches": 5}, {"name": "Player B", "goals": 7, "matches": 3}, {"name": "Player C", "goals": 6, "matches": 4}]```Expected Output:```python{ "Player A": 2.0, "Player B": 2.33, "Player C": 1.5}```

answer:def calculate_average_goals(player_stats): result = {} for player in player_stats: name = player["name"] goals = player["goals"] matches = player["matches"] if matches > 0: average_goals = round(goals / matches, 2) result[name] = average_goals return result

question:Write a python function to take a list of strings as input and return a list of those strings sorted by their length in descending order. If two strings have the same length, maintain their original order from the input list. Input: A list of strings, e.g., `["voice", "technology", "AI", "conference", "network"]`.Expected Output: A list of strings sorted by their length in descending order, e.g., `["technology", "conference", "network", "voice", "AI"]`.Note: Ensure that strings of the same length appear in the same order as they did in the input list.

answer:def sort_strings_by_length(string_list): # Create a list of tuples with (length, index, string) string_tuples = [(len(s), i, s) for i, s in enumerate(string_list)] # Sort the list of tuples by length in descending order sorted_tuples = sorted(string_tuples, key=lambda x: (-x[0], x[1])) # Extract the sorted strings from the tuples sorted_strings = [t[2] for t in sorted_tuples] return sorted_strings

question:Write a python function to calculate the average number of visits a general practitioner makes to a set of patients, where each patient has a specified number of visits. The function should take a list of integers as input, where each integer represents the number of visits for a patient. The function should return a float representing the average number of visits across all patients.For example, if the input list is `[3, 5, 2, 8, 6]`, the function should return `4.8` since the average of these numbers is 4.8.

answer:def calculate_average_visits(visits): total_visits = sum(visits) num_patients = len(visits) average_visits = total_visits / num_patients return average_visits

Released under the MIT License.

has loaded