Prime or composite
Class 11 Computer Science · Iterative Statements: Number Programs · Write the program · 4 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 reads an integer n and checks whether it is prime or composite. Numbers less than 2 are neither prime nor composite. Input: one line, n. Output: exactly one line, one of N is a prime number N is a composite number N is neither prime nor composite
Sample tests
Use these examples to check your program. Your output must match the Expected Output exactly.
13
13 is a prime number
21
21 is a composite number
Evaluation: when you submit, your program is also checked against 4 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)
A number from 2 upward is prime if no number between 2 and n - 1 divides it. The loop looks for a divisor and stops with break at the first one, because one divisor is enough to prove the number composite. Check numbers below 2 first: 0, 1 and negative numbers are neither prime nor composite.
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 · Alternating series · Right triangle of stars · Palindrome string · Linear search in a list · Search in a tuple · Character frequency with a dictionary · Circle with the math module