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.
Question
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 $\mathrm{x}$ days, $\mathrm{y}$ days and $\mathrm{z}$ days respectively to do the job alone. The formula to calculate the number of days if they work together is $\mathrm{xyz} /(\mathrm{xy}+\mathrm{yz}+\mathrm{xz})$ days where $\mathrm{x}, \mathrm{y}$, and $\mathrm{z}$ are given as input to the program.
✨ Free AI Tools for You
Powered by Chatterbot AI
Answer
You can use the following Python program to calculate the number of days it will take for three people (A, B, and C) to complete a job together using the given formula:
# Function to calculate the number of days to complete the work together
def calculate_days(x, y, z):
total_days = (x * y * z) / (x * y + y * z + x * z)
return total_days
# Main program
if __name__ == "__main__":
# Input the number of days each person takes to complete the work alone
x = int(input("Enter the number of days A takes to complete the work: "))
y = int(input("Enter the number of days B takes to complete the work: "))
z = int(input("Enter the number of days C takes to complete the work: "))
try:
# Calculate the total number of days to complete the work together
total_days = calculate_days(x, y, z)
print(f"The work will be completed in {total_days} days when A, B, and C work together.")
except ZeroDivisionError:
print("One or more of the inputs are zero, which makes the calculation invalid.")
Explanation:
Function
calculate_days
:Takes as input the number of days
x
,y
, andz
that person A, B, and C take to complete the work alone.Uses the given formula (\mathrm{xyz} /(\mathrm{xy}+\mathrm{yz}+\mathrm{xz})) to calculate the total number of days to complete the work if all three work together.
Main Program:
Prompts the user to enter the number of days
x
,y
, andz
for persons A, B, and C.Calls the
calculate_days
function and prints the result.Includes a try-except block to handle any division by zero errors if one of the inputs is zero.
India's 1st AI Doubt Solver for CBSE, JEE, and NEET
Ask a Question for Freeand then it's just ₹212 a month