gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
Make 10 line Python
- User
Make 10 line Python
- Assistant
Certainly! Here is a simple 10-line Python script that reads a list of numbers from a file, calculates their sum, and prints the result:
pythondef read_numbers(file_path): with open(file_path, 'r') as file: return [int(line.strip()) for line in file] def calculate_sum(numbers): return sum(numbers) def main(): file_path = 'numbers.txt' # Make sure this file exists with numbers numbers = read_numbers(file_path) total = calculate_sum(numbers) print(f"The sum of numbers is: {total}") if __name__ == '__main__': main()This script assumes there is a file named
numbers.txtwith one integer per line. Adjust the file path as necessary.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.