Back to the page

In the print window, choose “Save as PDF”.

doubtly doubtly.in

Write a program that prompts the user to input a positive integer.

Python · Updated 27 Jan 2024 · Read online: www.doubtly.in/write-a-program-that-prompts-the-user-to-input-a-positive-integer/

Write a program that prompts the user to input a positive integer. It should then output a message indicating whether the number is a prime number. A prime number is a number that is evenly divisible only by itself and 1. For example, the number 5 is prime because it can be evenly divided only by 1 and 5. The number 6, however, is not prime because it can be divided evenly by I, 2, 3, and 6.

num=int(input("Enter number: "))
k=0
for i in range(2,num//2+1):
    if(num%i==0):
        k=k+1
if(k<=0):
    print("Number is prime")
else:
    print("Number isn't prime")

Practise this on Doubtly (free)