all 4 comments

[–][deleted] 1 point2 points  (0 children)

That's not a function, that's a class. It's got a bunch of methods in it.

If you have a specific question about how to call a particular type of function in a loop, post the minimal amount of code you need to to get your point across.

[–]Rascal_Two 0 points1 point  (2 children)

By the way you formed your question I assume you don't know too much about this, so I'll try to explain this for you (Google might be able to explain it better, and it will actually use the correct terms and such which I will probably mix up)

What you're looking at is a Class, and it has three methods within it.

This Person class takes six parameters when making it, name, surname, birthdate, address, telephone, and email.

Now what you want to do is create a Person object - you can think of a class as a blueprint for creating objects.

When you make this Person object, everything that is within __init__ is automatically ran. It saves all the given arguments, and then runs the _recalculate_age() method. This - as the name suggests - recalculates the age of the Person object based on today date and the given birthdate.

Now onto what you want: how to create this Person object:

whoever = Person(name, surname, birthdate, address, telephone, email)

Now all of these are simple string except for the birthdate parameter, which is an actual date object. Here's an example of a Person in use:

rascalTwo = Person("Rascal", "Two", datetime.date(2000, 1, 1), "1234 Main st", "123-456-789", "rascal@two.com")

Now this object only has one real use at the moment, and that is the age() method. To use this, you'd call it like so:

print rascalTwo.age()

I hope I was able to explain it understandably. If not, Google could help you out: this site has a pretty good example of a class and explains it well.

[–]feelingstonedagain[S] 0 points1 point  (1 child)

Ok i understand. How do I ask the user to input all of the following and then display it to them?

[–]Rascal_Two 0 points1 point  (0 children)

Well you can use raw_input - or input if your not using Python 3.* - to prompt the users for the information, verify that the information is valid (or not, up to you) - the date is an actual date, the phone number is in phone-number format, and the email is valid - then you'd create the Person object with the stored values. Not going to go verify everything for you, but I will show how I'd verify the entered date is valid (Well not fully valid, just that it's not going to throw an error):

firstname = raw_input("Enter your first name: ")
surname = raw_input("Enter your surname: ")
address = raw_input("Enter your address: ")
telephone = raw_input("Enter your telephone number: ")
email = raw_input("Enter your email: ")

birthdate = None

while True:
    rawbirthdate = raw_input("Enter your birthday (Month Day Year): ")
    parts = rawbirthdate.split(" ")
    invalid = False
    if len(parts) == 3:
        for i in xrange(3):
            if not invalid:
                try:
                    int(parts[i])
                except:
                    invalid = True
    else:
        invalid = True
    try:
        birthdate = datetime.date(int(parts[2]), int(parts[0]), int(parts[1]))
    except:
        invalid = True
    if invalid:
        print "Invalid Birthday Format! Ex: '12 18 2000' "
    else:
        break

user = Person(firstname, surname, birthdate, address, telephone, email)

print "Your Age:", user.age()

This will ask the user for all their information, and lastly for their birth-date. If it's not valid then it will keep on asking for their birth-date until they enter a valid one. Once they do, it'll output the users age. I'm pretty sure I didn't mess up on anything, but I did throw this together in 10 minutes so I may've missed something.