Circle with the math module
Class 11 Computer Science · Python Modules · Write the program · 3 marks
- Read the question and the sample tests.
- Write your Python program in the editor.
- Run Code to check it on the sample tests (no marks).
- Submit Answer for evaluation: hidden tests award the marks. Nothing is saved here.
Question
Write a program that imports the math module and reads the radius r of a circle (an integer). Using math.pi, find the area (π r²) and the circumference (2 π r), then print the area rounded down with math.floor() and the circumference rounded up with math.ceil(). Input: one line, r. Output: exactly two lines in the form Area (floor): A Circumference (ceil): C
Sample tests
Use these examples to check your program. Your output must match the Expected Output exactly.
7
Area (floor): 153 Circumference (ceil): 44
1
Area (floor): 3 Circumference (ceil): 7
Evaluation: when you submit, your program is also checked against 3 hidden tests that you cannot see. Marks come from the hidden tests only. Each test you pass earns its marks, so a partly correct program gets part marks. Prompt text passed to input() is not counted as output.
Your program
Write the whole program, including any import lines it needs. The editor starts empty; Reset Code clears it. Submit your answer before leaving the page.
Approach (open it after you have tried)
import math makes the module's names available as math.pi, math.floor and math.ceil. floor() rounds down to the nearest integer and ceil() rounds up, so an area of 153.93... prints as 153 and a circumference of 43.98... as 44. Both return integers.
Practise all 65 Class 11 programs
This page has 10 programs. The complete Class 11 Python Lab has 65, and keeps your best score and chapter progress.
Other Class 11 programs: Simple interest · Grade from marks · Prime or composite · Alternating series · Right triangle of stars · Palindrome string · Linear search in a list · Search in a tuple · Character frequency with a dictionary