Question: a) Write a program that uses a while loop to print all divisors of a number supplied by the user. The program should also print

a) Write a program that uses a while loop to print all divisors of a number supplied by the user. The program should also print the sum of all the divisors and whether the number the user entered is a prime number or not. Note: The definition of a divisor is a number that divides another evenly (i.e., without a remainder) and the definition of a prime number is a number whose only divisors are 1 and itself.

b) Implement the same program as above using a for loop instead of a while loop. Which implementation do you think is the better choice for this problem? Discuss with a friend and/or a TA if you are unsure.

Sample Outputs (user input highlighted)

Enter an integer: 20

The divisors are:

1

2

4

5

10

20

The sum of the divisors is 42

The number is not prime.

Enter an integer: 19

The divisors are:

1

19

The sum of the divisors is 20

The number is prime!

use Python

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!