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)

Answered by Luca S. Python tutor

1006 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Create a python code to sum the number from 1 to 10.


Write a function that takes an imput (call it usr_in), the user's age (usr_age) and the user's name (usr_nm) and outputs the following string: "Hi, My name is [usr_nm], I am [usr_age] years old, and my favorite number is [usr_in]"


Explain how you would write a python program that takes a rectangle and a point in a 2D space as command-line arguments and checks if they intersect.


What can I do with Python?


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences