Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions