DEV Community

Cover image for Python Scenario Based Problem Solving..
Narasimma Radhakrishnan
Narasimma Radhakrishnan

Posted on

Python Scenario Based Problem Solving..

1.A book seller has three types of books:English books = 175,Science books = 245,Mathematics books = 385
He wants to arrange these books into boxes.

Conditions:

  1. Each box must contain an equal number of English books.
  2. Each box must contain an equal number of Science books.
  3. Each box must contain an equal number of Mathematics books.
  4. No books should be left over. The question asks us to find:
  5. The greatest number of boxes required.
  6. The number of books of each subject in one box.

solution :
1.TO find hcf for all the three numbers(175, 245,385)
2.That is the greatest number of boxes required.
3.To divide books with hcf value to find the exact number of each subject.

eng = 175
sci = 245
maths = 385

hcf = 1
for i in range(1, eng + 1):

    if eng % i == 0 and sci % i == 0 and maths % i == 0:
        hcf = i

print("Greatest number of boxes:", hcf)

print("English books in each box:", eng // hcf)
print("Science books in each box:", sci // hcf)
print("Maths books in each box:", maths // hcf)
Enter fullscreen mode Exit fullscreen mode

Output :

Greatest number of boxes: 35
English books in each box: 5
Science books in each box: 7
Maths books in each box: 11
Enter fullscreen mode Exit fullscreen mode

Top comments (0)