---
# System prepended metadata

title: Code Review H11C

---

# Code Review H11C

Compare these two pieces of code from a pythonic, style, and readability point of view and choose which one you prefer. When you choose one, you must justify your reasoning.

**review_1.py**
```
def check_password(password):
    
    if password == "password" or password == "iloveyou" or password == "123456":
        return "Horrible password"
    elif (len(password) >= 12 and any(x.isupper() for x in password) and
        any(x.isdigit() for x in password) and 
        any(x.islower() for x in password)):
        return "Strong password"
    elif len(password) >= 8 and any(x.isdigit() for x in password):
        return "Moderate password"
    else:
        return "Poor password"
   
if __name__ == '__main__':
    print(check_password("iheartsemesters"))
    # What does this do? 
```


**review_2.py**
```
def check_password(password):
    '''
    Takes in a password, and returns a string based on the strength of that password.

    The returned value should be:
    * "Strong password", if at least 12 characters, contains at least one number, at least one uppercase letter, at least one lowercase letter.
    * "Moderate password", if at least 8 characters, contains at least one number.
    * "Poor password", for anything else
    * "Horrible password", if the user enters "password", "iloveyou", or "123456"
    '''
    horrible_pw = ["password", "iloveyou", "123456"]
    digit = False
    upper = False

    if password in horrible_pw:
        return "Horrible Password"
    elif len(password) >= 8:
        for char in password:
            if char.isdigit():
                digit = True
            elif char.isupper():
                upper = True
        if digit and upper and len(password) >= 12:
            return "Strong Password"
        elif digit:
            return "Moderate Password"
    
    return "Poor Password"

if __name__ == '__main__':
    print(check_password("iheartsemesters"))
    # What does this do?
```


## AERO
1:
* The first one is more readable , however its efficiency is not high enough
2:
* The second one has higher efficiency, however it has lower readability, it need some comments.

Preferred: (1 or 2)
* 2 
* More procedural thinking

## BLINKER
1:
* Long conditions makes it harder for readability
* Only one line of code under each condition.

2:
* Docstring is always useful for reader to understand purpose of function

Preferred: (1 or 2)
* 2 
* It's easier to follow.


## CACTUS
1:
* comments
* Pythonic and easy to read

2:
* comments
* Has a docstring

Preferred: (1 or 2)
* why?
* 1 more pythonic has for loops that are easy to read and understand


## DORITO
1:
* no docstring for function
* Super long and confusing if statement


2:
* comments
* Better way of checking for bad passwords ('password', 'iloveyou', '123456')

Preferred: (1 or 2)
* 2


## ECHO
1:
* Simple structure
* Could have chosen better variable names ('x')
* Very long if statement (lines 11-13)

2:
* Many nested ifs and loops 
* Good documentation - has docstring, good variable names
* Easier to maintain - constants defined at the top of the code 

Preferred: (1 or 2)
* 3 (with combination of both two: documentation/constants from 2 and structure from 1)

