Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Write a program that asks for a user name and a password. It shows Welcome, Asha! only when the name is asha and the password is py123. Otherwise it says Wrong name or password.
and: both conditions must be True.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Plan. Both must be right, so we use and.
if name == "asha" and password == "py123":
Check. If the name is right and the password is wrong, True and False is False, so the else part runs. The message does not say which one was wrong. That is better for safety.
Log in to join the discussion.
Loading…