Bird
0
0

Which of the following is the correct way to check a username and password in Python on Raspberry Pi?

easy📝 Syntax Q12 of 15
Raspberry Pi - Security and Deployment
Which of the following is the correct way to check a username and password in Python on Raspberry Pi?
Aif username = 'pi' and password = 'raspberry':
Bif username = 'pi' or password = 'raspberry':
Cif username == 'pi' and password == 'raspberry':
Dif username == 'pi' or password == 'raspberry':
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct comparison operator

    In Python, '==' checks equality; '=' assigns values.
  2. Step 2: Check logical operators for authentication

    Both username and password must match, so use 'and' not 'or'.
  3. Final Answer:

    if username == 'pi' and password == 'raspberry': -> Option C
  4. Quick Check:

    Use '==' and 'and' for correct check [OK]
Quick Trick: Use '==' to compare and 'and' to require both true [OK]
Common Mistakes:
MISTAKES
  • Using '=' instead of '==' for comparison
  • Using 'or' instead of 'and' to check both credentials
  • Mixing assignment and comparison operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes