About float/double type number in range.

Joel Goldstick joel.goldstick at gmail.com
Wed Aug 26 03:58:50 EDT 2020


On Wed, Aug 26, 2020 at 3:43 AM ADITYA <gautam.goari123 at gmail.com> wrote:
>
>    Dear Sir/Ma’am
>
>    I am requesting you to satisfy me about float number in Range function,
>    because in the argument of range we can take integer but not double or
>    float whenever double as well as float are integer in nature but when we
>    use double/float in, it gives error that- “'float' object cannot be
>    interpreted as an integer.” If we want to increment the number by half or
>    quarter what can I do.
>
>    For ex- Range(1,3,0.5) I want it gives Output as [1 1.5 2 2.5 3)
>

Take a look at this:
>>> l = [i/2 for i in range(2,7)]
>>> l
[1.0, 1.5, 2.0, 2.5, 3.0]
>>>
The first line is a list comprehension which is a convenient way to
produce a list by performing an operation on each element in range.

In your code, you set the end of the range to 3 which will not include
3.  It stops at 2.
>
>
>    I am requesting to change the nature of increment number nature in above
>    example so that we can increase the number with half or quarter any point
>    value.
>
   if you want to increase by 1/4, use a range that is 4 times normal
integers. and divide each element by 4
>
>    Your Sincerely
>
>    Aditya Gautam
>
>    Saharsa (Bihar)
>
>    India
>
>    Postal Code- 852201
>
>
>
>
>
>
>
>
>
>
>
>    Sent from [1]Mail for Windows 10
>
>
>
>    [2][IMG] Virus-free. [3]www.avg.com
>
> References
>
>    Visible links
>    1. https://go.microsoft.com/fwlink/?LinkId=550986
>    2. http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient
>    3. http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays


More information about the Python-list mailing list