|
1 | 1 | # Basic-Python-Programs
|
2 |
| -Basic Python Programs |
| 2 | + |
| 3 | +<i>Our Python Code Repository is a community-driven platform for sharing high-quality Python programs. With contributions from members of the community, our repository contains a collection of Python codes for others to learn from and use. We welcome contributions from anyone who wants to share their code and follow our guidelines. Our moderators review all pull requests to ensure the quality and consistency of our repository. Join our community and contribute to creating a valuable resource for Python developers worldwide.</i></br> |
| 4 | +## How to Contribute |
| 5 | + |
| 6 | +1. Fork the repository to your GitHub account. |
| 7 | +2. Clone the repository to your local machine. |
| 8 | +3. Create a new branch for your changes. |
| 9 | +4. Make changes and commit them to your branch. |
| 10 | +5. Push your branch to your forked repository. |
| 11 | +6. Open a pull request to the original repository. |
| 12 | + |
| 13 | +## Guidelines for Contributions |
| 14 | + |
| 15 | +- Ensure the use of descriptive variable and function names. |
| 16 | +- Write meaningful code comments to describe a function.</br> |
| 17 | +Example- |
| 18 | +```python |
| 19 | +def binary_search(target, lst): |
| 20 | + """ |
| 21 | + Performs binary search on a sorted list to find the index of a target element. |
| 22 | +
|
| 23 | + Args: |
| 24 | + target (int): The target element to find in the list. |
| 25 | + lst (list): The sorted list to search in. |
| 26 | +
|
| 27 | + Returns: |
| 28 | + int: The index of the target element in the list, or -1 if it is not found. |
| 29 | + """ |
| 30 | + count_iterations = 0 # Counter for the number of iterations required to perform the search |
| 31 | + start_index = 0 # The starting index of the search range |
| 32 | + end_index = len(lst) - 1 # The ending index of the search range |
| 33 | + |
| 34 | + # Perform binary search until the target element is found or the search range is exhausted |
| 35 | + while start_index <= end_index: |
| 36 | + count_iterations += 1 |
| 37 | + mid_index = (start_index + end_index) // 2 # Calculate the midpoint index of the search range |
| 38 | + if target < lst[mid_index]: |
| 39 | + end_index = mid_index - 1 # Adjust the search range to the lower half |
| 40 | + elif target > lst[mid_index]: |
| 41 | + start_index = mid_index + 1 # Adjust the search range to the upper half |
| 42 | + else: |
| 43 | + return mid_index # The target element is found at the midpoint index |
| 44 | + |
| 45 | + return -1 # The target element is not found in the list |
| 46 | +``` |
| 47 | +- Write precise commit messages so that other fellow contributors understand what you are trying to do. |
| 48 | +- Please describe any test cases that failed or were enhanced, and any improvements to time/space complexity, when modifying existing code in your commit message.</br> |
| 49 | +Ex- if you have modified mid_index calculation to mid_index=start+(end-start)//2 in order to avoid integer overflowing |
| 50 | +```python |
| 51 | +mid_index=start+(end-start)//2 |
| 52 | +``` |
| 53 | +Commit message for the same would be: |
| 54 | +```Mid integer overflowing avoided```</br> |
| 55 | +Extended (optional) description could be: |
| 56 | +```The benefit of this formula is that it avoids integer overflow when calculating the midpoint index for large values of start and end. |
| 57 | +In the formula mid = (start + end) / 2, if start and end are large integers, adding them may exceed the maximum value that can be stored in an integer variable, leading to integer overflow and potentially incorrect results. |
| 58 | +``` |
| 59 | + |
| 60 | +- Include documentation for new features. |
| 61 | + |
| 62 | +<h4>If you have any questions or need help with contributing to the project, please reach out to us via GitHub issues</h4> |
| 63 | + |
| 64 | +<i><h3>We welcome any feedback, suggestions, or contributions to our project. Please feel free to reach out to us if you have any questions or would like to contribute.</h3></i> |
0 commit comments