Question 23: If Elif Else

Write a Python program to determine the power output of a machine based on its work done and the time taken.

  1. Ask the user for the machine’s name and store it in a variable called machine_name.
  2. Ask how much work the machine did (in joules) and store it in a variable called work_done (as a float).
  3. Ask how much time it took to complete the work (in seconds) and store it in a variable called time_taken (as a float).
  4. Calculate the power output using the formula:
     
    power = work_done / time_taken
  5. Use an if-elif-else structure to classify the machine’s performance based on power:
    • If power is greater than or equal to 1000, print:
      "Impressive, [machine_name]! Your power output is [power] watts. That's heavy-duty performance!"
    • If power is greater than or equal to 500 but less than 1000, print:
      "Good job, [machine_name]! Your power output is [power] watts. You're quite efficient!"
    • If power is greater than 0 but less than 500, print:
      "Keep improving, [machine_name]! Your power output is [power] watts. There's room for enhancement."
    • If time_taken is 0, print:
      "Error: Time cannot be zero. Please check the input values for [machine_name]."
Write what you are looking for, and press enter to begin your search!