Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Python 3.6.0 Write a function, called factor, which takes an integer, say

ID: 3819709 • Letter: U

Question

Using Python 3.6.0
Write a function, called factor, which takes an integer, say n, as a parameter and returns the first Number between 2 and n-1 which divides n. If no such number exists it returns -1
Sample output 1: Enter n: 15 The smallest divisor is : 3
Sample output 2: Enter n: 17 The smallest divisor is : -1
Sample output 3: Enter n: 16 The smallest divisor is : 2
Using Python 3.6.0
Write a function, called factor, which takes an integer, say n, as a parameter and returns the first Number between 2 and n-1 which divides n. If no such number exists it returns -1
Sample output 1: Enter n: 15 The smallest divisor is : 3
Sample output 2: Enter n: 17 The smallest divisor is : -1
Sample output 3: Enter n: 16 The smallest divisor is : 2

Write a function, called factor, which takes an integer, say n, as a parameter and returns the first Number between 2 and n-1 which divides n. If no such number exists it returns -1
Sample output 1: Enter n: 15 The smallest divisor is : 3 Write a function, called factor, which takes an integer, say n, as a parameter and returns the first Number between 2 and n-1 which divides n. If no such number exists it returns -1
Sample output 1: Enter n: 15 The smallest divisor is : 3
Sample output 2: Enter n: 17 The smallest divisor is : -1
Sample output 3: Enter n: 16 The smallest divisor is : 2 Sample output 2: Enter n: 17 The smallest divisor is : -1
Sample output 3: Enter n: 16 The smallest divisor is : 2

Explanation / Answer

python code:

def factor(n):
for i in range(2,n):
if(n%i == 0):
return i
return -1;
  
print("Enter n");
n = int(input().strip())
print("The smallest divisor is : ", factor(n))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote