You have already created a Circle Area Calculator in assignment 1.5. Remember? You implemented the formula and used a `PI` constant with the value of `3.14`.
Now that we know how to ask the user for input, we can make this script way more powerful. We can now ask the user to give us the circle radius, instead of hardcoding it in our code!
Let’s edit our `circle_area.py` script so that we ask the user to input the radius by asking them `”What is the radius of the circle?”`. You can now use this input, which you can convert to an integer number using the `int()` function, to calculate the area of this circle!
Please note: Play around with your script and see if you can make it crash. What happens, for instance, if you give an unexpected input like a word? You will learn how to prevent this crash in the next assignment.
-!- CODE language-bash -!-$ python3 circle_area.py
What is the radius of the circle? 8
$ python3 circle_area.py
What is the radius of the circle? 99
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!