# Use Wolfram|Alpha in Python?

**URL:** <https://community.wolfram.com/t/use-wolfram-alpha-in-python/11098>\
**Category:** Questions\
**Tags:** computer-science, wolfram-alpha, curated-data, equation-solving, external-interfaces\
**Created:** [August 14, 2017, 10:58pm UTC](https://community.wolfram.com/t/use-wolfram-alpha-in-python/11098 "2017-08-14T22:58:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nadiasingh23](https://avatars.discourse-cdn.com/v4/letter/n/67e7ee/32.png) [@nadiasingh23](https://community.wolfram.com/u/nadiasingh23)\
**Post date:** [August 14, 2017, 10:58pm UTC](https://community.wolfram.com/t/use-wolfram-alpha-in-python/11098/1 "2017-08-14T22:58:05Z")

</div>

Hi there! I’m developing a program in Python to calculate the energy of a primary cosmic ray particle using the NKG-function. Part of the process involves solving an equation in x in the form ax^1.2 + bx^2.2 + cx^3.2 + dx^4.2 - s = 0, where a, b, c, d and s are known variables.

I’ve installed the Wolfram Alpha package using pip, and am working in the IDE PyCharm. The code correctly calculates the value of x, but I think it is stored as a string, rather than a float. In order to use this x value in further calculations, I need to convert it into a float. I know how to do this in Python, but was wondering how this is done using the Wolfram Alpha language?

This is the section of the code so far:

```
client = wf.Client("app_ID") #app_ID is the app id

q = "Solve 274770*x **1.2 + 8271.8*x** 2.2 + 79.555*x **3.2 + 0.22184*x** 4.2 - 35435557377 = 0"
res = client.query(q)
answer = next(res.results).text
print(answer)

ra1 = answer
print("ra1:", ra1)

ra2 = (k*r0**eta) / (measured_density_a*(h*ra1**0.2 + g*ra1 **1.2 + i*ra1** 2.2 + e*ra1**3.2))
print("ra2", ra2)

```

This is the output when I run the code:

```
x = 385.279
ra1: x = 385.279

Traceback (most recent call last):
  File "C:/Users/Nadia/PycharmProjects/Particle_Energy/energy_code/complete_code_wolfram.py", line 282, in <module>
    ra2 = (k * r0 **eta) / (measured_density_a * (h * ra1** 0.2 + g * ra1 **1.2 + i * ra1** 2.2 + e * ra1 ** 3.2))

TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'float'

```

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![imfonky](https://avatars.discourse-cdn.com/v4/letter/i/ee7513/32.png) [@imfonky](https://community.wolfram.com/u/imfonky)\
**Post date:** [October 26, 2018, 10:23pm UTC](https://community.wolfram.com/t/use-wolfram-alpha-in-python/11098/2 "2018-10-26T22:23:29Z")

</div>

Hello!

I think your error here is not related with wolfram.

Python basically says that one of the variables on the left of the \*\* operator is a string.  
Try to print ra1 and see if it’s numeric, if yes, cast it with float(…) or int(…)
