Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add solution for code challenge issue #4, use of operators #21

Merged
merged 1 commit into from
Dec 29, 2024

Conversation

RamonColmenares
Copy link

@RamonColmenares RamonColmenares commented Dec 29, 2024


name: solution review
about: A template PR for code review with a checklist

Challenge: Use of Operators

Instructions:

  1. Create a loop to go through each element in the list called lista_de_elementos.
  2. Check the type of each element:
    • If the element is a number (integer or float), check if it is below the defined threshold (umbral).
      • Print "Approved" if the value is below the threshold.
      • Print "Rejected" otherwise.
    • If the element is a string (str), skip the comparison with the threshold.
  3. Implement two counters:
    • One to count the number of approved elements.
    • One to count the number of rejected elements.
  4. Count the elements that are of type string (str) and print the total at the end of the loop.
  5. Print the total of approved and rejected elements at the end of the code.

Initial Parameters:

threshold = -10
elements_list = [10, 3.14, "7", -5, "2.718", 42, "Python", -8.9, "Hello", 100.5, "World", -15, "GPT-3", 5.5, "AI", -20, "2023", 123, "OpenAI", -2.5, "Example"]

# Development of the main code loop.
# In this space, you must write the code following the instructions from the previous cell.



print("Total approved: ", approved)
print("Total rejected: ", rejected)
print("Total strings: ", string_count)

Expected Output:

At the end of the loop, the program should return:

  • The total number of approved elements.
  • The total number of rejected elements.
  • The total number of strings (str).

Helpful Links

  1. for loop in Python
    Documentación oficial sobre cómo usar los bucles for en Python:
    for statement - Python Docs

  2. if statement in Python
    Documentación oficial sobre cómo usar las sentencias if en Python:
    if statement - Python Docs

Files

  • The file name describes the function's behavior
  • There is a module docstring in the function file
  • The test file's name matches the function file name -
    /tests/test_file_name.py
  • There is a module docstring in the tests file

Unit Tests

  • The test class has a helpful name in PascalCase
  • The test class has a docstring
  • Every unit test has
    • A helpful name
    • A clear docstring
    • Only one assertion
    • There is no logic in the unit test
  • All tests pass
  • There are tests for defensive assertions
  • There are tests for boundary cases

Function Docstring

  • The function's behavior is described
  • The function's arguments are described:
    • Type
    • Purpose
    • Other assumptions (eg. if it's a number, what's the expected range?)
  • The return value is described
    • Type
    • Other assumptions are documented
  • The defensive assertions are documented using Raises:
    • Each assumption about an argument is checked with an assertion
    • Each assertion checks for only one assumption about the argument
  • Include 3 or more (passing!) doctests

The Function

  • The function's name describes it's behavior
  • The function's name matches the file name
  • The function has correct type annotations

Strategy

Do's

  • Variable names help to understand the strategy
  • Any comments are clear and describe the strategy
  • Lines of code are spaced to help show different stages of the strategy

Don'ts

  • The function's strategy is not described in the documentation
  • Comments explain the strategy, not the implementation
  • The function does not have more comments than code
    • If it does, consider finding a new strategy or a simpler implementation

Implementation

  • The code passes the formatting checks
  • The code passes all Ruff linting checks
  • The code has no (reasonable) Pylint errors
    • In code review, you can decide when fixing a Pylint error is helpful and
      when it's too restricting.
  • Variables are named with snake_case
  • Variable names are clear and helpful
  • The code follows the strategy as simply as possible
  • The implementation is as simple as possible given the strategy
  • The code includes defensive assertions
  • Defensive assertions include as little logic as possible

@RamonColmenares RamonColmenares self-assigned this Dec 29, 2024
@RamonColmenares RamonColmenares linked an issue Dec 29, 2024 that may be closed by this pull request
Copy link

@hectordacb hectordacb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing the code

Copy link

@hectordacb hectordacb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code passed the entire checklist. Great job, @RamonColmenares 💪

@hectordacb hectordacb merged commit c6b95fd into main Dec 29, 2024
10 checks passed
@hectordacb hectordacb deleted the 4-challenge-use-of-operators branch December 29, 2024 21:19
hectordacb added a commit that referenced this pull request Jan 5, 2025
…erators

Feat: add solution for code challenge issue #4, use of operators
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Challenge: Use of Operators
2 participants