Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: Check the Password | Python if-else Statement
Conditional Statements in Python
course content

Course Content

Conditional Statements in Python

Conditional Statements in Python

1. Python if Statement
2. Python if-else Statement
3. Python if-elif-else Statement

bookChallenge: Check the Password

Task
test

Swipe to show code editor

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.

  1. Check if password == correct_password to decide the login result.
  2. Use the ternary operator to handle both success and failure in one line.
  3. Assign the result to login_message and print it.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 5
toggle bottom row

bookChallenge: Check the Password

Task
test

Swipe to show code editor

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.

  1. Check if password == correct_password to decide the login result.
  2. Use the ternary operator to handle both success and failure in one line.
  3. Assign the result to login_message and print it.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 5
toggle bottom row

bookChallenge: Check the Password

Task
test

Swipe to show code editor

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.

  1. Check if password == correct_password to decide the login result.
  2. Use the ternary operator to handle both success and failure in one line.
  3. Assign the result to login_message and print it.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Task
test

Swipe to show code editor

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.

  1. Check if password == correct_password to decide the login result.
  2. Use the ternary operator to handle both success and failure in one line.
  3. Assign the result to login_message and print it.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 2. Chapter 5
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt