Code:
class User(): """A class to describe typical user and it's info.""" def __init__(self, username, password, first_name, age, birthdate, last_name, middle_name=None, location='', email=''): """Initialize first and last names, age, birthdate and location(optional)""" self.username = username self.password = password self.email = email self.first_name = first_name self.last_name = last_name self.middle_name = middle_name self.age = age self.birthdate = birthdate def confirm_user(self): enter_use = "Please enter your username." use = input(enter_use) if use == user_1(use): enter_password = "Please enter your password." password = input(enter_password) if password == user_1(password): logged_in_user = user_1 print('Login successful.') elif use == user_2(use): enter_password = "Please enter your password." password = input(enter_password) if password == user_2(password): logged_in_user = user_2 print('Login successful.') elif use == user_3(use): enter_password = "Please enter your password." password = input(enter_password) if password == user_3(password): logged_in_user = user_3 print('Login successful.') elif use != user_1(username) and user_2(username) and user_3(username): print('Invalid username. If you wish to make an account that uses that username, please sign up.') elif password != user_1(password) and user_2(password) and user_3(password): print('Invalid password. If you wish to make an account that uses that password, please sign up.') else: print('Invalid username and password. If you wish to make an account that uses that password and username, please sign up.') def greet_user(self): full_name = self.first_name + self.middle_name + self.last_name print('Welcome, ' + (str(full_name.title())) + '!') def post(self): """Defining the action of a user posting a message on a website.""" ask = "\nDo you want to post a message?\n(y/n)" ans = input(ask) if ans == 'y': post_what = "\nPlease enter what you want to post:" post_this = input(post_what) print(logged_in_user + ':' + post_this) else: print('You are welcome to post a message next time!') user_1 = User('matty1234*', 'matjersey12341234', 'matjersey@hotmail.com', 'mat', 'jersey', 37, '1983/12/31', 'Canada, Ontario, Toronto, Scarborough, Brimley Road') user_2 = User('<wdwith92>', 'asf2vel', 'sarah_elens@hotmail.com', 'sarah', 'elens', 39, '1981/10/30', 'Canada, Ontario, Toronto, Scarborough, Brimley Road') user_3 = User('alice&wonderland', 'jonny374', 'jon', 7, '2012/12/24', 'lee', 'elens', 'Canada, Ontario, Toronto, Scarborough, Brimley Road') users = [user_1, user_2, user_3] for user in users: self.confirm_user() self.greet_user() self.post()
What is wrong???
Error:
https://stackoverflow.com/questions/65431234/self-is-not-defined December 24, 2020 at 05:37AMTraceback (most recent call last): File "C:\Users\di\OneDrive\文档\alice_coding_stuff\python files\User.py", line 66, in self.confirm_user() NameError: name 'self' is not defined
没有评论:
发表评论