0
\$\begingroup\$

So I started learning how to code about 6 days ago and suddenly realized that I've really only been referencing my book and myself without any outside input. I'm learning python and the most complex thing I've done on my own so far is a simple class that handles 'user' info with a bunch of tests to make sure it works.

It works but I'm wondering how my formatting holds up, if my comments are detailed enough, and if there is anything I'm doing that could be improved. I've also never used this site before so I'm sorry in advance if I mess anything up.

# 9-5: LOGIN ATTEMPTS
class User:
    """Define what a user is"""
    def __init__(self, user_name, first_name, last_name, login_attempts = ''):
        self.first_name = first_name
        self.last_name = last_name
        self.user_name = user_name
        self.login_attempts = 0

    # Prints out the info on a user, properly formatted
    def describe_user(self):
        print(f"{self.user_name} is {self.first_name.title()} {self.last_name.title()}")

    # Greets a user
    def greet_user(self):
        print(f"Welcome back, {self.user_name}")

    # Tracks login attempts
    def increment_login_attempts(self):
        self.login_attempts += 1

    # Resets tracked login attempts
    def reset_login_attempts(self):
        self.login_attempts = 0


# Setting up users with info
user_1 = User("K-pitty", "Kreg", "Pissy")
user_2 = User("GGx", "Sarah", "Gukko")

# Testing login tracking
    # User 1
user_1.increment_login_attempts()
print(user_1.login_attempts)
user_1.reset_login_attempts()
print(user_1.login_attempts)
print("-----\n")
 
    # User 2
user_2.increment_login_attempts()
user_2.increment_login_attempts()
user_2.increment_login_attempts()
print(user_2.login_attempts)
user_2.reset_login_attempts()
print(user_2.login_attempts)
print("-----\n")

# Testing user info
user_1.describe_user()
user_2.describe_user()
print("-----\n")

# Greeting users
user_1.greet_user()
user_2.greet_user()
print("-----\n")

I have no idea if this is formatted correctly so I'm also attaching an image.enter image description here

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Please describe in the title what your code does instead of your concerns with it. Leave the concerns for the question body instead. \$\endgroup\$
    – Mast
    Apr 7 at 4:40
  • 2
    \$\begingroup\$ What exactly is the goal of this code? There seems to be some unused code. What are your intentions there? Why would you reset login attempts or increment login attempts without actually attempting to log in? It's hard to review a program that doesn't fully make sense. \$\endgroup\$ Apr 7 at 4:48
  • \$\begingroup\$ When improving the title, fix the indentation of the first declaration in the code block: The pixel raster looks more promising. \$\endgroup\$
    – greybeard
    Apr 7 at 7:04
  • \$\begingroup\$ "I'm wondering how my formatting holds up" check out pypi.org/project/black \$\endgroup\$
    – gvee
    Apr 8 at 15:59

1 Answer 1

0
\$\begingroup\$

In your init code

  1. You did not use the login_attempts
  2. The default login_attempts should be 0:
    def __init__(self, user_name, first_name, last_name, login_attempts=0):
        self.first_name = first_name
        self.last_name = last_name
        self.user_name = user_name
        self.login_attempts = login_attempts

Other than that, your code is fine.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.