Exercises · Q12
Q.Write a program to calculate in how many days a work will be completed by three persons A, B and C together. A, B, C take x days, y days and z days respectively to do the job alone. The formula to calculate the number of days if they work together is xyz/(xy + yz + xz) days where x, y, and z are given as input to the program.
Yanam BieapTextbookSubjective· 3mImportance★★★★★est
80% · 39/49 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Read x, y, z, apply days = xyz/(xy + yz + xz) and print — for the sample inputs 6, 8, 12 the three finish the work together in about 2.67 days.
The formula is supplied, so the whole task is a faithful translation into one arithmetic expression, with parentheses guaranteeing the entire denominator is computed before the division.
# Days to finish a work when A, B and C work together
x = float(input("Days taken by A alone: "))
y = float(input("Days taken by B alone: "))
z = float(input("Days taken by C alone: "))
days = (x * y * z) / (x*y + y*z + x*z)
print("Working together, the work is completed in", round(days, 2), "days")
Key lines:
- The denominator must be parenthesised:
x*y*z / x*y + y*z + x*zwould divide only by x, then multiply by y — a completely different (and wrong) value. This is the pitfall the exercise is really about. round(days, 2)keeps the report readable; drop it if full precision is wanted.
Sample run (an example — any positive inputs work):
Days taken by A alone: 6
Days taken by B alone: 8
Days taken by C alone: 12 …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.