Course Content
Conditional Statements in Python
Conditional Statements in Python
Challenge: Check the Password
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.
- 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
and print it.
Thanks for your feedback!
Challenge: Check the Password
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.
- 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
and print it.
Thanks for your feedback!
Challenge: Check the Password
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.
- 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
and print it.
Thanks for your feedback!
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.
- 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
and print it.