Ask the user for a number and output the smallest divisor, bigger than one, for the inputted number. Output "Prime" if the number is a prime number.

num = int(input("Enter a number: ")) if num < 0: print("The number can't be less than 0.") else: div = 1 found_divisor = False while div <= num and not found_divisor: div += 1 if num % div == 0: found_divisor = True if not found_divisor or div==num: print("The number is a PRIME number.") else: print(div)

LS

Related Python Mentoring answers

All answers ▸

Write a simple number guessing game, give the user 3 tries to guess a number between 1 and 10


How do I check if a number is prime using a python program?


Describe both For-loops and While-loops and explain how you can simulate the effect of a for loop with a while loop with an example.


How do I use for loops in Python?