Skip to content

Instantly share code, notes, and snippets.

@seanwittmeyer
Created July 11, 2018 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanwittmeyer/6684ba0c616207058e827c5ab2b6d272 to your computer and use it in GitHub Desktop.
Save seanwittmeyer/6684ba0c616207058e827c5ab2b6d272 to your computer and use it in GitHub Desktop.
range choice python component by jonah hawk for the udan project
"""Provides a scripting component.
Inputs:
min: Minimum value for the range
max: Maximum value for the range
count: the length of the list of number, including the min and max values.
i: index choice of the list
Output:
a: The a output variable"""
__author__ = "jonah.hawk"
__version__ = "2018.05.18"
import math
import decimal
if not min:
min = 0
if not max:
max = 1.00
if not count:
count = 10
if not i:
i = 0
if min == max:
max = min + 0.001
min = decimal.Decimal(min)
max = decimal.Decimal(max)
count = decimal.Decimal(count)
def drange(x, y, jump):
while x < y:
yield float(x)
x += decimal.Decimal(jump)
theRange = []
stepFloat = (max-min)/(count-1)
step = round(stepFloat, 3)
print(step)
theRange = list(drange(min, max, step))
ind = int(i)
if max not in theRange:
theRange.append(float(max))
print(theRange)
if i >= len(theRange):
ind = (len(theRange) -1)
S = step
R = theRange
I = theRange[ind]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment