Consider this Python code snippet running on a Raspberry Pi. What will it print if the user enters the password 'raspberry'?
password = input('Enter password: ') if password == 'raspberry': print('Access granted') else: print('Access denied')
Check the exact string compared in the if condition.
The code compares the input to the string 'raspberry'. If they match exactly, it prints 'Access granted'. Otherwise, it prints 'Access denied'.
When building a user login system on a Raspberry Pi, which method is best to store user passwords securely?
Think about what makes it hard for attackers to recover the original password.
Hashing passwords with a salt means passwords are transformed into a fixed string that cannot be reversed easily. This protects passwords even if the storage is compromised.
Look at this code snippet. It should grant access if the password is 'pi123', but it always prints 'Access denied'. What is the problem?
password = input('Enter password: ') if password is 'pi123': print('Access granted') else: print('Access denied')
Check how string comparison works in Python.
The 'is' operator checks if two variables point to the same object, not if their values are equal. For string value comparison, '==' must be used.
Which option contains the correct syntax for this Raspberry Pi Python login snippet?
password = input('Password: ') if password == 'secret' print('Welcome!') else: print('Try again')
Python requires a specific punctuation after conditions.
In Python, an if statement must end with a colon ':' before the indented block.
Given this dictionary storing usernames and hashed passwords, how many users are registered?
users = {
'alice': '5f4dcc3b5aa765d61d8327deb882cf99',
'bob': '202cb962ac59075b964b07152d234b70',
'carol': '098f6bcd4621d373cade4e832627b4f6'
}
print(len(users))Count the number of keys in the dictionary.
The dictionary has three keys: 'alice', 'bob', and 'carol'. The len() function returns the number of keys.