9.6. Conditional Recap

9.6.1. Assignments

# %% About
# - Name: Conditional Recap Auth
# - Difficulty: easy
# - Lines: 4
# - Minutes: 5

# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% English
# 1. Write authentication system
# 2. User will provide two strings: `USERNAME` and `PASSWORD`
# 3. Check if `USERNAME` is in the `DATABASE` and if the `PASSWORD` matches
# 4. If both matches, then define variable `result` with value `True`
# 5. Run doctests - all must succeed

# %% Polish
# 1. Napisz system uwierzytelniania
# 2. Użytkownik poda dwa ciągi znaków: `USERNAME` i `PASSWORD`
# 3. Sprawdź czy `USERNAME` jest w `DATABASE` i czy `PASSWORD` pasuje
# 4. Jeżeli oba pasują, to zdefiniuj zmienną `result` z wartością `True`
# 3. Uruchom doctesty - wszystkie muszą się powieść

# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python 3.9+ required'

>>> assert result is not Ellipsis, \
'Assign your result to variable `result`'

>>> assert type(result) is bool, \
'Variable `result` has invalid type, should be bool'

>>> from pprint import pprint
>>> pprint(result)
True
"""

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`

# %% Imports

# %% Types
result: bool

# %% Data
DATABASE = {
    'mwatney': 'Ares3',
    'mlewis': 'Nasa69',
    'rmartinez': 'Mav3',
    'avogel': 'Chem1',
    'bjohanssen': 'Root0',
    'cbeck': 'DoctorNo1'
}

USERNAME = 'mwatney'
PASSWORD = 'Ares3'

# %% Result
result = ...