Please write a useful program
- User
Please write a useful program
- Assistant
Sure! Here is a simple program that calculates the average of a list of numbers:
def calculate_average(numbers): if not numbers: return "List is empty" average = sum(numbers) / len(numbers) return average # Example usage: number_list = [5, 10, 15, 20, 25] average_result = calculate_average(number_list) print(f"The average is: {average_result}")This program defines a function called
calculate_averagethat takes a list of numbers as input. It first checks if the list is empty and returns an appropriate message if it is. Otherwise, it calculates the average by summing up all the numbers in the list and dividing it by the total count of numbers. Finally, it returns the average.In the example usage, a list of numbers
[5, 10, 15, 20, 25]is passed to thecalculate_averagefunction, and the resulting average is printed to the console.Feel free to modify this program to suit your specific needs or add additional functionalities.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.