-6

I getting an error for my below code:

import wolframalpha

ask = input("Question:- ")
app_id = "E82747-Y2LGY6EKH3"

client = wolframalpha.Client(app_id)

res = client.query(ask)

answer = next(res.results).text

print (answer)  

Error I am getting:

**Traceback (most recent call last):   File "test.py", line 8, in <module>
    answer = next(res.results).text StopIteration
**

What am I doing Wrong?

Rahul
  • 10,830
  • 4
  • 53
  • 88
Vipul
  • 11
  • 1
  • 1
    please format your code and then explain your issue – WhatsThePoint Jul 06 '17 at 09:51
  • 4
    Please re-take the [tour], read [ask], and then *ask a question*. You only throw (unformatted) code at us, without any information about what you try to achieve, what result you expect and what kind of problem arises. – Christian König Jul 06 '17 at 09:51

2 Answers2

0

I've just run your code (with the question "temperature of the sun") and it seems to work fine, giving me an answer of 5772 K.

StopIteration is raised when there are no more items in the iterable (res.results). What question did you ask, and are you sure it gave an answer?

Try printing res.results before the call to next to check what it returned.

timlyo
  • 2,086
  • 1
  • 23
  • 35
-1

Try using a try: and except: block. This should allow you to print something if it doesn't find a result.

Eno Gerguri
  • 639
  • 5
  • 22