Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
BlueHost Web Hosting

Bonsai Boy of New York Bonsai Trees and Accessories

Website Domains Names & Hosting | Domain.com

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Instant Grammar Checker - Correct all grammar errors and enhance your writing

Liquid Web Cloud VPS Hosting

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

12,336 questions

16,793 answers

573 users

How to implement a range of float numbers function in Python

1 Answer

0 votes
def frange(start, stop=None, step=None):
    if stop == None:
        stop = start
        start = 0.0
    if step == None:
        step = 1.0
    while True:
        if step > 0 and start >= stop:
            break
        elif step < 0 and start <= stop:
            break
        yield "%g" % start 
        start = start + step
 
 
print("\nfrange(3.14, 3.17, 0.01)")
for i in frange(3.14, 3.17, 0.01):
    print(i, end=" ")
  
print("\n\nfrange(-1.5, 3.5, 0.5)")
for i in frange(-1.5, 3.5, 0.5):
    print(i, end=" ")
   
print("\n\nfrange(3.14)")
for i in frange(3.14):
    print(i, end=" ")
 
print("\n\nfrange(1.4, 3.6)")
for i in frange(1.4, 3.6):
    print(i, end=" ")  
     
print("\n\nfrange(0.5, 2.5, -0.5)")
for i in frange(0.5, 2.5, -0.5):
    print(i, end=" ")
     
print("\n\nfrange(6.5, 2.5, -0.5)")
for i in frange(6.5, 2.5, -0.5):
    print(i, end=" ")
   
print("\n\nfrange(5.5, 1.5)")
for i in frange(5.5, 1.5):
    print(i, end=" ")
 
 
'''
run:
    
frange(3.14, 3.17, 0.01)
3.14 3.15 3.16 3.17 
 
frange(-1.5, 3.5, 0.5)
-1.5 -1 -0.5 0 0.5 1 1.5 2 2.5 3 
 
frange(3.14)
0 1 2 3 
 
frange(1.4, 3.6)
1.4 2.4 3.4 
 
frange(0.5, 2.5, -0.5)
 
 
frange(6.5, 2.5, -0.5)
6.5 6 5.5 5 4.5 4 3.5 3 
 
frange(5.5, 1.5)
 
'''

 




answered May 12, 2019 by avibootz
edited May 12, 2019 by avibootz
...