write the code to create a class in python
- User
write the code to create a class in python
Assistant
pythonclass Person: """A simple class representing a person.""" def __init__(self, name: str, age: int): """Constructor that runs when a new Person object is created.""" self.name = name # public attribute self.age = age # public attribute def greet(self) -> str: """Return a greeting string.""" return f"Hello, my name is {self.name} and I am {self.age} years old." def have_birthday(self) -> None: """Increment the person's age by one.""" self.age += 1 print(f"Happy birthday, {self.name}! You are now {self.age}.") # Example usage if __name__ == "__main__": alice = Person("Alice", 30) print(alice.greet()) # -> Hello, my name is Alice and I am 30 years old. alice.have_birthday() # -> Happy birthday, Alice! You are now 31.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.