Sobes.tech
Junior — Senior

Optimization and correction of the work calculation program

livecode

Task condition

Write a program that prompts the user for the values of force and distance, then calculates work = force * distance.

Requirements:

  • Eliminate code duplication by placing input in a separate function.
  • Correct the typo in the output (replace "Workdone" with "Work done").
  • Improve code readability.
while True:
    force = int(input("Enter the force value: "))
    if force > 0:
        break

while True:
    distance = int(input("Enter the distance value: "))
    if distance > 0:
        break

print("The Work done is", force * distance)