Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Challenge: Implementing a Password Checker with if-else Logic | Mastering Python if-else Statements
Conditional Statements in Python
course content

Kurssisisältö

Conditional Statements in Python

Conditional Statements in Python

1. Mastering Python if Statements
2. Mastering Python if-else Statements
3. Mastering Python if-elif-else Statements

book
Challenge: Implementing a Password Checker with if-else Logic

Tehtävä

Swipe to start coding

You have the following code that checks if the password entered by the user matches the expected password. However, the code uses multiple if statements, making it less efficient and a bit confusing. Your task is to improve and debug the code by using the ternary operator to simplify the logic.

  • Check if password == correct_password to decide the login result.
  • Use the ternary operator to handle both success and failure in one line.
  • Assign the result to login_message.
  • If the password is correct: "Login successful!"
  • If the password is incorrect: "Incorrect password, try again."

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 5
toggle bottom row

book
Challenge: Implementing a Password Checker with if-else Logic

Tehtävä

Swipe to start coding

You have the following code that checks if the password entered by the user matches the expected password. However, the code uses multiple if statements, making it less efficient and a bit confusing. Your task is to improve and debug the code by using the ternary operator to simplify the logic.

  • Check if password == correct_password to decide the login result.
  • Use the ternary operator to handle both success and failure in one line.
  • Assign the result to login_message.
  • If the password is correct: "Login successful!"
  • If the password is incorrect: "Incorrect password, try again."

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 5
Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Pahoittelemme, että jotain meni pieleen. Mitä tapahtui?
some-alt