Skip to content

Instantly share code, notes, and snippets.

@Jubix-pixel
Created October 16, 2022 22:13
Show Gist options
  • Save Jubix-pixel/954713451546d3f4d8ec500371066750 to your computer and use it in GitHub Desktop.
Save Jubix-pixel/954713451546d3f4d8ec500371066750 to your computer and use it in GitHub Desktop.
class User:
"""A class that checks about a user."""
def __init__(self, first_name, last_name, age, job, sex):
"""Attributes of the user."""
self.first_name = first_name
self.last_name = last_name
self.age = age
self.job = job
self.sex = sex
@property
def first_name(self):
return self.__first_name
@first_name.setter
def first_name(self, first_name):
if not isinstance(first_name, str):
raise TypeError("First Name be a String!")
self.__first_name = first_name
@property
def last_name(self):
return self.__last_name
@last_name.setter
def last_name(self, last_name):
if not isinstance(last_name, str):
raise TypeError("Last Name must be String!")
self.__last_name = last_name
@property
def job(self):
return self.__job
@job.setter
def job(self, job):
if not isinstance(job, str):
raise TypeError("Job must be String!")
self.__job = job
@property
def age(self):
return self.__age
@age.setter
def age(self, age):
if age < 0:
print("Invalid, Pls Enter a Valid Age!")
if not isinstance(age, int):
raise TypeError("Age must be an Int!")
self.__age = age
@property
def sex(self):
return self.__sex
@sex.setter
def sex(self, sex):
if not isinstance(sex, str):
raise TypeError("Sex must be String!")
self.__sex = sex
def describe_user(self):
"""A Method to describe the summary of the user."""
print("{}.{} is a {}, who is {} years old.".format(self.__first_name, self.__last_name, self.__job, self.__age))
def greet_user(self):
"""A method to send a personalized greeting to the user."""
if self.__sex == 'Male':
print("Good Day, Mr {}.{}".format(self.__first_name, self.__last_name))
print("I Trust You are having a Wonderful Day")
elif self.__sex == 'Female':
print("Good Day, Miss {}.{}".format(self.__first_name, self.__last_name))
print("I Trust You are having a Wonderful Day")
else:
print("Please Enter your Sex!")
user1 = User("Efenedo", "Jubilee", 20, "Software Developer and Actor", 'Male')
user2 = User("Vera", "Efenedo", 30, "Civil Servant", "Male")
user2.greet_user()
user2.describe_user()
@Jubix-pixel
Copy link
Author

I Tried my First User Object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment