29)Divisible by 2, 3, 4, 5, 6, 8, 9
def divisible(num):
if num % 2 == 0:
print("Divisible by 2")
if num % 3 == 0:
print("Divisible by 3")
if num % 4 == 0:
print("Divisible by 4")
if num % 5 == 0:
print("Divisible by 5")
if num % 6 == 0:
print("Divisible by 6")
if num % 8 == 0:
print("Divisible by 8")
if num % 9 == 0:
print("Divisible by 9")
num = int(input("Enter a number: "))
divisible(num)
Output:
Enter a number: 150
Divisible by 2
Divisible by 3
Divisible by 5
Divisible by 6
30)Write the smallest and the biggest two digit prime number
def prime_numbers():
smallest = 0
biggest = 0
num = 10
while num <= 99:
count = 0
i = 1
while i <= num:
if num % i == 0:
count += 1
i += 1
if count == 2:
if smallest == 0:
smallest = num
biggest = num
num += 1
print("Smallest =", smallest)
print("Biggest =", biggest)
prime_numbers()
Output:
Smallest = 11
Biggest = 97
There are four Mobile Phones in a house. At 5 a.m, all the four Mobile Phones will ring together. Thereafter, the first one rings every 15 minutes, the second one rings every 20 minutes, the third one rings every 25 minutes and the fourth one rings every 30 minutes. At what time, will the four Mobile Phones ring together again?
# LCM
a = 15
b = 20
c = 25
d = 30
i = 1
while not (i % a == 0 and i % b == 0 and i % c == 0 and i % d == 0):
i += 1
print(i, "minutes")
Output:300 minutes
A book seller has 175 English books, 245 Science books and 385 Mathematics books. He wants to sell the books in a box, subject-wise in equal numbers. What will be the greatest number of the boxes required? Also find the number of books for each subject in a box.
a = 175
b = 245
c = 385
i = 1
hcf = 1
while i <= a:
if a % i == 0 and b % i == 0 and c % i == 0:
hcf = i
i += 1
print("Number of boxes =", hcf)
print("English books =", a // hcf)
print("Science books =", b // hcf)
print("Maths books =", c // hcf)
Output:
Number of boxes = 35
English books = 5
Science books = 7
Maths books = 11
Amicable Numbers
Pairs of two integers(a,b)
Sum of divisor of a=b
Sum of divisor of b=a
Eg:220,284
220=1,2,4,5,10,11,20,22,44,55,110
SUM:284
284=1,2,4,71,142
SUM:220
1184,1210
2620,2924
5020,5564
6232,6368
def amicable(a, b):
sum1 = 0
sum2 = 0
i = 1
while i < a:
if a % i == 0:
sum1 += i
i += 1
i = 1
while i < b:
if b % i == 0:
sum2 += i
i += 1
if sum1 == b and sum2 == a:
print("Amicable Numbers")
else:
print("Not Amicable Numbers")
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
amicable(a, b)
Output:
Enter first number: 5020
Enter second number: 5564
Amicable Numbers
Top comments (0)