Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

Please write a useful program

  1. User

    Please write a useful program

  2. 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_average that 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 the calculate_average function, and the resulting average is printed to the console.

    Feel free to modify this program to suit your specific needs or add additional functionalities.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.