livepython.net

89. Python Program to Print Prime Numbers up to N

HardNested loops

Overview

Put the whole chapter together: range(), a nested loop, a flag with break, and a counter.

Problem Statement

A prime number is a whole number of 2 or more that divides evenly only by 1 and itself, like 2, 3, 5 and 7. Read a whole number n and print every prime from 2 to n, each on its own line, then the number of primes in the format Total: 4. If there are none, print only Total: 0. For example, for 10:

2
3
5
7
Total: 4

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Input

One value per line, in this order. Example:

10

Output

The output for that example:

2
3
5
7
Total: 4

The tests try 4 different inputs.

Learn this firstChapter 10 · Nested Loops, break and continue in Python
solution.py
# write your code here

EXPECTED OUTPUT

12
23
35
47
5Total: 4

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.