Ask Question
13 October, 13:35

Write a program that prompts the user for an integer and thenprints out all prime numbers up to that integer. For example, when the user enters 20, the program should print out:

2

3

5

7

11

13

17

19

Note: A prime number is not divisible by any number except 1and itself.

+1
Answers (1)
  1. 13 October, 15:34
    0
    n=int (input ("Enter number upto which you want to print prime numbers:/n")) #taking input of n in integer type ...

    for i in range (1, n) : #looping over 1 to n.

    pr=True #taking pr to be True ...

    for div in range (2, i) : #looping over 2 to i ...

    if i%div==0:#if i is divisible by div then it is not prime

    pr=False#making pr false

    if pr and i!=1: #condition for printing

    print (str (i)) #printing the prime numbers ...

    Explanation:

    In the python program we have checked for every integer up to n that is is not divisible by any integer between 2 to n-1 both inclusive if it is then it is not a prime number.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program that prompts the user for an integer and thenprints out all prime numbers up to that integer. For example, when the user ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers