Python Class tutorial

Hi there i have completed a an exercise from a book and wanted you guys to have a look, I think its giving me back the results needed but i cant tell for sure if i have answered the questions rightly and the code i wrote is not error prone.

better coding suggestions are welcome:

User Class:

Test 1:

1 Make a class called User.
2 Create two attributes called first_name and last_name
3 Create several other attributes that are typically
stored in a user profile.
4 Make a method called describe_user() that prints a summary
of the user’s information.
5 Make another method called greet_user() that prints a personalized greeting to the user.
6 Create several instances representing different users, and call both methods for each user

class User:
    def __init__(self, firstname, lastname, age, education, married, employed):
        self.firstname = firstname
        self.lastname = lastname
        self.age = age = education
        self.married = married
        self.employed = employed
        self.login_attempts = 0

    def describe_user(self):
        return f'Profile: {self.firstname} {self.lastname}, {self.age} years old, a {}, fully {self.married}, and {self.employed}'

    def greet_user(self):
        # Print a personalized message for your user
        return f"Hi {self.firstname} you are welcome:"

 # Instances created for many people

profile = User('Amin', 'Umar', 47, 'Developer', 'Married', 'Employed')
gyasi = User('Gyasi', 'Kobina', 52, 'Boga', 'Married', 'Employed')
akos = User('Maa', 'Akos', 47, 'Trader', 'Married', 'Employed')
kyei = User('Kyei', 'Mensa', 25, 'boys boys', 'Married', 'Employed')

# Calls

Please note, am new and want to know if i was able to answer the test questions well, and if the coding is logical:
i will be glad if anyone can help with another code tackling the test their own way, seeing another code will help me a lot. Thank you all in advance

Test 2

Login Attempts:
1 Add an attribute called login_attempts to your User class from the previous exercise.
2 Write a method called increment_login_attempts() that increments the value of login_attempts by 1.
3 Write another method called reset_login_attempts() that resets the value of login_attempts to 0.
4 Make an instance of the User class and call increment_login_attempts() several times.
5 Print the value of login_attempts to make sure it was incremented properly, and then call reset_login_attempts().
Print login_attempts again to make sure it was reset to 0

    def increment_login_attempt(self, attempt):
        # A Method that increments the value of login_attempts by 1
        self.login_attempts += attempt

    def reset_login_attempts(self):
        # A method to reset login_attempts to 0
        self.login_attempts -= self.login_attempts
        print(f"login attempts is reset to: {self.login_attempts}")

#  instance
gyasi.login_attempts = 2    # modified login from original value.
gyasi.increment_login_attempt(1)     # Increment of loging attempts.

print(gyasi.login_attempts)  # printing and expecting 3 as attempts .

# an attempt to display the reset user login_attempt to 0:
gyasi.login_attempts = 5

Test 1:

Item 2 says “Create two attributes called first_name and last_name”. You’ve named them “firstname” and “lastname”, without the underscores.

Why does the profile in describe_user say “fully”? What does “Fully married” mean?

Test 2:

Item 2 says “Write a method called increment_login_attempts() that increments the value of login_attempts by 1”, but your method will increment by attempt.

In self.login_attempts -= self.login_attempts, why do you have self.login_attempts -= self.login_attempts? There’s a shorter way of setting self.login_attempts to 0.

Thank you very much Mathew Barnett, i appreciate it very much your observation.
for the firstname and lastnames i trust that was lack of paying attention to that line of instruction. taken note now.

on the fully married line, i think i was trying my hands on extending the f string formatting

the method that was to handle the increment, i added it attempt as a parameter. in the instance below i think i am supplying that increment number as 1
gyasi.increment_login_attempt(1) # Increment of login attempts

last one is your suggestion on a best way to get the reset to 0 coded. am looking forward to your assistance with a code on it.
as a learner am grateful you went through the code.

Test 2, item 2 says that you should increment it by 1, but you’re incrementing by attempt. OK, so you’re telling it that attempt is 1, but that’s not what was asked for, and how likely is it that you’ll want to increment by anything other than 1 anyway?

The comment in the method is incorrect because it’s incrementing by attempt, which might not be 1!

Keep it simple:

    def increment_login_attempts(self):
        self.login_attempts += 1

(I only just noticed that you wrote increment_login_attempt instead of increment_login_attempts.)

And then:


As for how to reset self.login_attempts to 0, that’s just:

        self.login_attempts = 0