Editor

Login Validator

Beginner · Write the code · from Python If-Else: Conditions, Elif, Nested Ifs, and Ternary

From the lesson: Python If-Else: Conditions, Elif, Nested Ifs, and Ternary

Every day you make hundreds of decisions. If it's raining, you grab an umbrella. If the traffic light is red, you stop. If your phone battery is below 20%, you look for a charger. These are all conditional decisions - you check something and act based on the result.

Read the lesson

Write a login validator. Two variables are given: username and password.

Rules:

  • If username is "admin" and password is "secret123", print "Welcome, admin!"
  • If username is "admin" but password is wrong, print "Wrong password"
  • For any other username, print "User not found"
  • Expected output for username = "admin", password = "wrong":

    Wrong password
    username = 'admin'
    password = 'wrong'
    # Write the login validation logic

    More if else exercises

    All Python exercises · 50 practice problems · Control Flow quiz