A Person Class

In a society of wizards and magical beings, age is a sensitive subject. It's not unusual to find a 500-year-old wizard with the look of a teenager. However, in this society, it's impossible to have a negative age! Your task is to create a Person class with name and age attributes in Python. The Person class should be robust enough to prevent the creation of a Person with negative age, by raising a ValueError exception.
Input
Output
alice=Person('Alice', 25); print(alice.age)
25
bob=Person('Bob', -25); print(bob.age)
ValueError: Age can't be negative
Note: Age is considered negative if it's less than 0. It's not considered negative if it's exactly 0.
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue