make an apples and oranges counter for pyhtohn
- User
make an apples and oranges counter for pyhtohn
Assistant
Apple and Orange Counter in Python
Here's a simple Python program that counts apples and oranges:
class FruitCounter: def __init__(self): self.apples = 0 self.oranges = 0 def add_apple(self, count=1): """Add apples to the counter""" self.apples += count print(f"Added {count} apple(s). Total apples: {self.apples}") def add_orange(self, count=1): """Add oranges to the counter""" self.oranges += count print(f"Added {count} orange(s). Total oranges: {self.oranges}") def get_counts(self): """Return the current counts""" return {"apples": self.apples, "oranges": self.oranges} def reset(self): """Reset both counters to zero""" self.apples = 0 self.oranges = 0 print("Counters reset to zero") # Example usage if __name__ == "__main__": counter = FruitCounter() # Add some fruits counter.add_apple(3) counter.add_orange(2) counter.add_apple() counter.add_orange(5) # Get current counts counts = counter.get_counts() print(f"\nCurrent counts: {counts}") # Reset the counter counter.reset()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.