python - skip a section of programming -
I am trying to program one kind of long system as part of my computing course. When I was programming, I came to the point that when I input my username "Jaysmith" it asks a user again. I think it should be left directly at the password check. Any advice or errors have been greatly appreciated. Thanks!
#seetting variables user_name = "l.parker" password = "password1" user_name_2 = "j.smith" password2 = "password2" user = "user0" #USERNAME check if input (" What is your username? ") == user_name: print (" Hello Luke ") user ==" user1 "alif input (" what is your username? ") == user_name_2: print (" Hello John ") user = = "User2" else: print ("this is not correct") left () #PASSWORD Check if user == "user1": If input ("What is your password?") == Password: print ("You Successfully logged in ") un The print ("This is not correct") quit () elif user == "user2": If input ("What is your password?") == password2: print ("You have logged in successfully") and: Leave the print ("this is not correct") ()
you accidentally By using the comparison operator ( ==
) instead of the assigned operator ( =
) on this line:
User = = "User1" should be: user = "user1"
plus you are calling input (already) several times.
But the more scalable solution puts the user in the object and it is similar to storing many users, such as:
class user (object): def __init __ (self, user name, password, normal_name = none): Self.username = username self.password = password self.common_name = common_name users = [user ('l.parker', 'password1', 'Luke') , User ('jesmith', 'password2', 'john')] name = input ('what is your username?') #Users Users = no bring nothing to the actors: if u.username == name: user = u brake # a user matches? If there is no user: print ('that is not right') quit () password = input ('what is your password?') #password if user.password! = Password print ('this' is not correct)) Skip () Print (' Dear '), you have successfully logged in!' Format (user.common_name))
Comments
Post a Comment