Python 2.3

Circle Area Calculator 2.0

  • Fully automatically graded on code quality, style, structure and functionality
  • Students write their solution in an online IDE in their LMS
  • Check for Python code plagiarism

Pre-requisites:

  • Print statement.
  • Input function.
  • Variables.

Learning goals:

  • Put input statements into practice.
Get access to an autograder, plagiarism checker and online IDE for this assignment now!

Task:

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.

Example usage:

-!- CODE language-bash -!-$ python3 circle_area.py
What is the radius of the circle? 8
200.96

$ python3 circle_area.py
What is the radius of the circle? 99
30775.14

Learn more:

Start teaching Python now

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!

Book a demo now!

Happy educators

  • Educators who use CodeGrade have less stress.
  • Educators who use CodeGrade have happier and more successful students.
  • Educators who use CodeGrade have a simpler teaching workflow.

Schedule a personalized tour of CodeGrade today.