12. Generate Prime Numbers Up to N

Acceptance — 0 accepted 0 submissions

Easy
No topics listed
No companies listed
Write a Python program that asks the user to enter a number N. Then find all prime numbers from 2 up to N and store them in a list. Print the list as the final output. A prime number is a number greater than 1 that has no factors other than 1 and itself. For example, if the user enters 10, the output should be [2, 3, 5, 7]. The program must take N as input from the user.

Example 1

Input
10
Output
[2, 3, 5, 7]

Explanation Prime numbers from 2 to 10 are 2, 3, 5, 7

Example 2

Input
2
Output
[2]

Explanation 2 is the only prime number up to 2

Example 3

Input
1
Output
[]

Explanation There are no prime numbers up to 1 so list is empty

Acceptance —
Accepted 0
Submissions 0
Auto-save
Saved Ln 1, Col 1
Submit a solution to see its status here.
Input
Expected Output
[2, 3, 5, 7]
No results yet
Run your code to test it against the sample cases.
Problem List