Practical 1 - COMP100 Practical 3 PDF
Practical 1 - COMP100 Practical 3 PDF
Practical 3
1. Divisibility Checker
A common test for divisibility by 3 is to add the individual digits of an integer. If the resulting sum is divisible
by 3 then so is the original number. Program this test in python without the use of strings. Input an integer
from the user, then calculate and output whether the input integer is divisible by 3 or not, using the given
technique.
If for example, the input integer is 234, the resulting sum is: 2+3+4=9, and since 9 is divisible by 3, then we
may output that 234 is divisible by 3.
You must reduce the sum of the individual digits to an integer that is < 20 before testing for divisibility i.e. if
the sum is >= 20, your algorithm must add the digits of the resulting sum.
If for example, the input integer is 999, the resulting sum is: 9+9+9=27, and since it is >=20, we sum
2+7=9 then since 9 is divisible by 3, we may output that 999 is divisible by 3.
This procedure should be repeated until the sum is < 20.
2. Abundant numbers
A positive integer is said to be abundant if the sum of all its proper factors is greater than the integer itself.
The proper factors of an integer are all those integers that divide into the original integer without remainder
but excludes the original integer.
Examples:
The sum of proper factors of the integer 6 are 1 + 2 + 3 = 6. Therefore 6 is not an
abundant number.
The sum of proper factors of the integer 12 are 1 + 2 + 3 + 4 + 6 = 16. Therefore 12
is an abundant integer.
The first few abundant integers are 12,18,20,24, and 30.
Write a python program that will generate all abundant numbers up to and including the first odd abundant
number. No inputs from the user are required.
3. Primes
A prime number is a positive integer that has no other divisors besides 1 and itself. Write a python program
that inputs two positive integers A and B from the user, then calculates and outputs the sum of all the prime
numbers between A and B inclusive.
Page 1 of 1