-3

Why would it say Login successful and Login not successful without the return True/False?

def passwords(name,password):
  data = [("Peter", "thepeter"), ("James", "thejames")]
  for x in data:
    if x[0]==name and x[1]==password:
      print("Login successful")
      return True
    else:
      print("Login not successful")
      return False
name1=input("Name:")
password1=input("Password:")
passwords(name1,password1)
Sam
  • 387
  • 4
  • 17
niklas2705
  • 33
  • 1
  • 6
  • I don't understand your question. Could you be more precise? – IcesHay Jan 17 '20 at 09:39
  • You might use the result of `passwords()` in *other* code, e.g. `if passwords(name1, password1): do_something_else()`-- you can't (easily) use the printed message to screen in other code, it's just for the user – Chris_Rands Jan 17 '20 at 09:40
  • If you want to see the tre/false also make the last line `print(passwords(name1,password1))` or assign the result to a vriable and print that. – Ocaso Protal Jan 17 '20 at 09:44
  • Not sure what your question is, but the "login not successful" part should be after the `for` loop, not inside it. Currently it will only check the first user/password. – interjay Jan 17 '20 at 09:46
  • I´m sorry this is my first time I learn a programming language and im European. Anyways. I don´t get why it wouldn`t say ("Login succesful") without the *return True* if I type the password in correct. Cause i typed print ("Login succesfull") and the *else*-function is irrelevant cause the *if*-function is already True? But if I do it without the returns it says "Login successful Login not successful" – niklas2705 Jan 17 '20 at 09:46
  • @OcasoProtal THANK YOU! That´s actually my question! I´m just bad at explaining I guess. Thank you all! – niklas2705 Jan 17 '20 at 09:48

1 Answers1

0

It does print "Login successfull/Not Successful" though, but you can also use the function like this if you use return:

a = passwords(someone, password)

Now if it returns True, a will be True. If it instead returns False, a will be False.

Tonechas
  • 13,398
  • 16
  • 46
  • 80
Noah.Ehrnstrom
  • 172
  • 1
  • 12