With this function, we can check if a number is an integer:
while True:
try:
x = int(input("Please enter a number: "))
break
except ValueError:
print(“Oops! That was no valid number. Try again…”)
I’ve got some problems:
When I type “109poit”, I’ve got this error message:
“Unexpected token ‘poit’”
When I type “109asdrgfase5”, I’ve got this error message:
“name ‘109asdrgfase’ is not defined”
When I type “109l” it works, whereas it’s not an integer! As a consequence, when I type “109loit”, I’ve got the error message: “Unexpected token ‘oit’”, whereas I should get “Unexpected token ‘loit’”.
I seems to act like that only with the letter “l”!!
So I really don’t get anything. What’s more it’s a function found in the help guide, so I shouldn’t have so many problems with this routine!
because you started this discussion here, I assume that you are running this in Rhino, right?
If so, Rhino does not use the “classic” Python command line, but its own. So, you should use rhinoscript.GetInteger(), for example. It should make the script a lot simpler.
Thank you Guilio, it works fine. So how to know if a Pyhton command works fine with Rhino? For example, I use the command Print and there is no problem with that one
In this case command-line instructions definitely do not work. The reason is that there is no OS-based command line. We might investigate ways to make this compatible with the Rhino command line, but it seems a lot of work for little gains.
In general, functions will work. It’s just mostly mouse picking and command line things, that have to work differently depending on the environment.