python / pythondotorg

Source code for python.org
https://www.python.org
Apache License 2.0
1.5k stars 594 forks source link

Implement Handling for Negative Range (l > r) in Python's range() Function #2422

Closed code-with-dhruv closed 6 months ago

code-with-dhruv commented 6 months ago

Issue Title

Implement Handling for Negative Range (left > right) in Python's range() Function

Description

Currently, when using Python's range() function with parameters where the start value is greater than the end value (e.g., range(30, 3)), it doesn't provide a default behavior or return value. This issue aims to add handling for such cases by returning -1 as the default value when left > right.

Steps to Reproduce

  1. Call range(30, 3) in Python code.
  2. Note that the return value is currently undefined or not handled.
  3. The default value for positive range() is +1 [Step value]
  4. Logically it should be -1 default if range(left,right) where left>right

Expected Behavior

After implementing the proposed handling, calling range(30, 3) should return -1.

Additional Information

Proposed Solution

Add logic to the range() function or its handling code to check if the start value is greater than the end value. If so, return -1 as the default value.

Tasks

Environment

Md template is generated using GPT 3.5 openAI

Mariatta commented 6 months ago

This issue tracker is for Python.org website, not for Python programming language.

code-with-dhruv commented 6 months ago

My bad