Reputation: 43
I am trying to get this class to work by passing in this information however it does not pass the information in. What am i doing wrong?
Here is the code:
class User:
def __init__(self, first_name, last_name, user_name, password, email):
self.first_name = first_name
self.last_name = last_name
self.user_name = user_name
self.password = password
self.email = email
def describe_user(self):
print("{self.first_name}" + " " + "{self.last_name}")
print("Your user_name is {self.user_name}")
print("Your password is {self.password}")
print("Your email is {self.email}")
def greet_user(self):
print("Hello {self.first_name}")
my_name = User('Eric', "Tekell", "tech1329", "5555", "[email protected]")
my_name.describe_user()
my_name.greet_user()
your_name = User("John", "Wayne", "wayne55", "6666", "[email protected]")
your_name.describe_user()
Upvotes: 1
Views: 43
Reputation: 192
You need the letter f
before your strings. It's called an F-STRING. Ex)
x = 5
print(f"x is equal to {x}")
That Would Print Out x is equal to 5
So Your Code Would Be:
class User:
def __init__(self, first_name, last_name, user_name, password, email):
self.first_name = first_name
self.last_name = last_name
self.user_name = user_name
self.password = password
self.email = email
def describe_user(self):
print(f"{self.first_name}" + " " + f"{self.last_name}")
print(f"Your user_name is {self.user_name}")
print(f"Your password is {self.password}")
print(f"Your email is {self.email}")
def greet_user(self):
print(f"Hello {self.first_name}")
my_name = User('Eric', "Tekell", "tech1329", "5555", "[email protected]")
my_name.describe_user()
my_name.greet_user()
your_name = User("John", "Wayne", "wayne55", "6666", "[email protected]")
your_name.describe_user()
Upvotes: 0
Reputation: 388
You have to put an 'f' before the string in order to give format:
class User:
def __init__(self, first_name, last_name, user_name, password, email):
self.first_name = first_name
self.last_name = last_name
self.user_name = user_name
self.password = password
self.email = email
def describe_user(self):
print(f"{self.first_name}" + " " + "{self.last_name}")
print(f"Your user_name is {self.user_name}")
print(f"Your password is {self.password}")
print(f"Your email is {self.email}")
def greet_user(self):
print(f"Hello {self.first_name}")
my_name = User('Eric', "Tekell", "tech1329", "5555", "[email protected]")
my_name.describe_user()
my_name.greet_user()
your_name = User("John", "Wayne", "wayne55", "6666", "[email protected]")
your_name.describe_user()
Upvotes: 2