Last answered:

08 Aug 2022

Posted on:

28 Jul 2022

0

Error for pi value on Spyder & Google Colab

I'm trying to do this a few different ways, but pi value is giving me a syntax error:

radius = float(input("Please enter the circle radius: ")
pi_value = 3.14159
area = pi*radius**2
print('You entered', radius, 'area of the circle is', area)

runfile('C:/Users/LENOVO/Variables_Ch4.py', wdir='C:/Users/LENOVO')
  File ~\Variables_Ch4.py:9
    pi_value = 3.14159
    ^
SyntaxError: invalid syntax

3 answers ( 0 marked as helpful)
Instructor
Posted on:

28 Jul 2022

0

Hey Priya,

Thank you for your question!

The reason you are getting the error is because you are missing a closing parenthesis at the end of the first line:

radius = float(input("Please enter the circle radius: "))

Once you correct this, your code will raise a second error stemming from the third line, which should read as follows:

area = pi_value*radius**2



Hope this helps!

Kind regards,
365 Hristina

Posted on:

04 Aug 2022

0

Hey Hristina,

Apologies for the delayed response, returning to the same problem, the issue persists on Spyder IDE, which calls it a 'separator' error. Running the code on Google Colab works fairly well (exhibit A). Running other codes on Spyder has not given me any errors yet.

p.s. I paused the Python Bootcamp lesson for a wee bit to get a head start on some of the other Fundamentals lessons, hence the delay in responding.A Spyder ErrorGoogle Colab

Instructor
Posted on:

08 Aug 2022

0

Hey again Priya,

Thank you very much for the follow-up! Don't worry to come back to this problem whenever you are ready with the rest of the courses.

It's great that the code is working as expected on Google Colab! Here is one very final modification that I could suggest. The math library in Python has the value of pi built-in and ready to use. That is, you don't need to define a variable storing the value of pi - Python already has this covered! Below, I have applied just that. I have also introduced another function called round() which rounds the answer to a desired number of significant figures.
image.png
Regarding the issue with Spyder, this seems to be a common problem lately. Let me re-direct you to the following thread:
https://365datascience.com/q/f24043be44
For the time-being, the issue can be resolved by either downgrading Anaconda, or by simply using a different IDE - Visual Studio, PyCharm, Jupyter notebook, all of which are discussed in the course. You can, of course, continue using Google Colab if it works well for you.

Hope this helps!

Kind regards,
365 Hristina

Submit an answer