VoxCommando
Help and Support (Using VoxCommando) => Python Scripting => Topic started by: Haddood on August 11, 2014, 04:36:06 AM
-
I am trying to calculate the square root of subtracting 2 numbers ...
I tried
sqrt (x)
I get error global name sqrt not defined
I tried
math.sqrt
I get error global name math not defined
not sure how to do it :bonk :bonk ... help appreciated
def distance(x,y):
distance= sqrt(x-y)
return str(distance)
-
Hi Haddood, I tried following in VC and it works
PY.ExecString result=({1}{3}{2})**.5
{1} is x
{2} is y
{3} is the computationally sign
here the command group (the math.xml is required in the VC payload folder)
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.0.0.5-->
<commandGroup open="True" name="math square root" enabled="True" prefix="" priority="0" requiredProcess="" description="">
<command id="620" name="square root" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
<action>
<cmdType>PY.ExecString</cmdType>
<params>
<param>result=({1}{3}{2})**.5</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
<action>
<cmdType>OSD.ShowText</cmdType>
<params>
<param>{LastResult}</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
<phrase>square root</phrase>
<phrase>from</phrase>
<payloadRange>1,5000</payloadRange>
<payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">payloads\math.xml</payloadFromXML>
<payloadRange>1,5000</payloadRange>
</command>
</commandGroup>
The python code will not work with negative numbers!
-
If you want to use math.sqrt(x)
then at the top of your python code you need to write
import math
-
also your distance function does not look right.
try this:
import math
def distance(x,y):
temp = x**2 + y**2
distance= math.sqrt(temp)
return str(distance)
print distance(5,6)
-
Many thanx James ... That did the trick ... My learning curve of python is pretty flat :bonk
Kalle thanks for the feedback, I needed to solve it within python ... I will keep you method for when i need sqrt inside VC