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
Answered by Luca S. Python tutor

1070 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

How could I write a program to convert Km/h to m/s in python


How would you get a piece of code to print the numbers 1 to 10


How do For Loops work?


When to use a dectionary or a list


We're here to help

contact us iconContact ustelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences