Basic python code - how to wrap value in "for i in" loop with conditional?

import rhinoscriptsyntax as rs
import math

if y<x:
print “domain error”
elif str(y) is 0:
print “y cannot be zero”
else:
print "domain set between “+str(int(x))+” and "+str(int(y))
countOffRange = range(int(x),int(y))
if z>(y-x):
for i in countOffRange:
i = range(0,int(z))+int(x):
print "test range "+str(i)
else:
for i in countOffRange:
print "test range "+str(i)

#make while loop so that if the range between x and y is less than z then
#wrap values until the count off is equal to z

hello,

wrapping means using the modulus. f.e. someList[index%listLength] -> if index = 11 and listLength = 10 you will get item = 1 from someList.

1 Like

@youngjaechung Could you post your code in a code block like this:

```
<code>
```

Python has meaningful indentation, so stripping them out leads to ambiguity and syntax errors.

A few comments:

compares a string to an integer, and always evaluates to false. Also, use the == operator to test for equality, not is, which can give you unexpected results.

No idea what this is supposed to do, but you shouldn’t be modifying your counter variable within the loop… also a syntax error due to the colon at the end of the line.

1 Like

You can even get syntax highlighting by specifying the language:

Also, uploading a file is good (as this lets us see how you implemented the code, set type hints etc.).

1 Like