User 클래스

다음 프롬프트를 사용하여 User라는 새 클래스를 생성합니다.


예시 #1

User 클래스 생성

일반적인 프롬프트

Create a class call User
add first_name, last_name, age, email, phone, login_attempts, and password attributes

Python 프롬프트

VSCode에서 파일을 생성하고 이름을 user_class.py로 지정하고 다음 코드를 입력합니다.

"""
Create a class call User
add first_name, last_name, age, email, phone, login_attempts, and password attributes
"""

제안을 수락하려면 Enter 키를 계속 누릅니다. Amazon Q Developer가 다음 코드를 생성합니다.

Amazon Q Developer 제안
class User:
    def **init**(self, first_name, last_name, age, email, phone, login_attempts,
password): 
        self.first_name = first_name 
        self.last_name = last_name 
        self.age =age
        self.email = email 
        self.phone = phone 
        self.login_attempts = login_attempts
        self.password = password

    def describe_user(self):
        print(f"User's name is {self.first_name} {self.last_name}.")
        print(f"User's age is {self.age}.")
        print(f"User's email is {self.email}.")
        print(f"User's phone number is {self.phone}.")
        print(f"User's login attempts is {self.login_attempts}.")
        print(f"User's password is {self.password}.")

    def greet_user(self):
        print(f"Hello {self.first_name} {self.last_name}!")

    def increment_login_attempts(self):

예시 #2

User 클래스 계속해서 생성

Enter 키를 계속 누르면 Amazon Q Developer가 계속해서 클래스를 추가/생성합니다.

일반적인 프롬프트

엔터만 입력할 것이기 때문에 추가로 입력할 내용이 없습니다.

Python 프롬프트

코드 제안의 끝으로 가서 Enter 키를 누릅니다. 그러면 Amazon Q Developer가 클래스에 다음 코드를 추가할 것입니다.

    --> We are hitting enter three times to get to the end of the suggestion. No need to type anything.
  • 현재 코드:

    def reset_login_attempts(self):
        self.login_attempts = 0
        print(f"Login attempts: {self.login_attempts}")

    
    def change_password(self, new_password):
        self.password = new_password
        print(f"Password: {self.password}")
Amazon Q Developer 제안
class User:
    def **init**(self, first_name, last_name, age, email, phone, login_attempts,
password): 
        self.first_name = first_name 
        self.last_name = last_name 
        self.age =age 
        self.email = email 
        self.phone = phone 
        self.login_attempts = login_attempts
        self.password = password

    def describe_user(self):
        print(f"User's name is {self.first_name} {self.last_name}.")
        print(f"User's age is {self.age}.")
        print(f"User's email is {self.email}.")
        print(f"User's phone number is {self.phone}.")
        print(f"User's login attempts is {self.login_attempts}.")
        print(f"User's password is {self.password}.")

    def greet_user(self):
        print(f"Hello {self.first_name} {self.last_name}!")

    def increment_login_attempts(self):
        self.login_attempts += 1
        print(f"Login attempts: {self.login_attempts}")

    def reset_login_attempts(self):
        self.login_attempts = 0
        print(f"Login attempts: {self.login_attempts}")

    def change_password(self, new_password):
        self.password = new_password
        print(f"Password: {self.password}")

Last updated