class userpass: users = {"meryem":"4444","ahmet":"sehir123","gakkos":"2323"} inventory = {'asparagus': [10, 5], 'broccoli': [15, 6], 'carrots': [18, 7], 'apples': [20, 5], 'banana': [10, 8], 'berries': [30, 3], 'eggs': [50, 2], 'mixed fruit juice': [0, 8], 'fish sticks': [25, 12], 'ice cream': [32, 6], 'apple juice': [40, 7], 'orange juice': [30, 8], 'grape juice': [10, 9]} market_inventory = [] customers_basket = [] def login(self): while True: #added login = raw_input('Username:') if login in self.users.keys(): psw = raw_input('Password:') if self.users[login] == psw: print 'Successfully logged in!','\n','Welcome,',login,"Please choose one of the following options by entering the corresponding menu number." break #added else: print 'Your user name and/or password is not correct. Please try again!' else: print "Your user name and/or password is not correct. Please try again!"
Output:>>> log = userpass()
>>> log.login()
Username:gakkos
Password:2323
Successfully logged in!
Welcome, gakkos Please choose one of the following options by entering the corresponding menu number.
>>>
recapping/learning while providing solution , wont mind if someone will correct me, i appreciate that.i assume you hv done this in python 2.x (raw_input function available) so i left out the brackets in print statement.
i added while and break statement so the code will keep asking for correct username & password
swallow osama bin laden