Now that we have worked with variables, we can start working with a special type of variable: constants. A constant is a variable that, like the name suggests, does not change value (or has a “constant” value). Variable names are written in lowercase but, the convention is to give variables that do not change their value (i.e. constants) an uppercase name: e.g. `GRAVITY`.
For our second formula, we will define two variables that we need in order to calculate the area of a circle, `PI` and `radius`. As always, use the correct names for your variables and assign `PI` the value of `3.14`.
Again, your program should only print the solution of the calculation. Call your program `circle_area.py`. The example output below is for a circle with a radius of `5`.
Please note: It is usually a bad practice to define your own common constants like pi, as they are already available in Python’s math module. You will learn more about the math module later in this course.
-!- CODE language-bash -!-$ python3 circle_area.py
CodeGrade is your virtual teaching assistant for your coding classroom. You teach, CodeGrade takes care of the rest.
With our 40+ built-in fully automatically graded Introduction to Python assignments for university-level courses, you can start teaching Python at your institution with confidence now. Or, scale your classroom with CodeGrade's tools.
Book a personal 30-minute demo now and we'll show you how to get started with CodeGrade in less than 1 hour!