Question: Problem Statement Write a Python function named convertTemp that takes two parameters: temps A list of temperature values. tempScale A character representing the

Problem Statement


Write a Python function named convertTemp that takes two parameters:

  1. temps – A list of temperature values.
  2. tempScale – A character representing the temperature scale (\"C\" for Celsius or \"F\" for Fahrenheit).

The function should evaluate the provided temperature scale using an if/elif statement:

  • If tempScale is \"F\", convert each temperature from Fahrenheit to Celsius using the formula: C = (F - 32) * 5 / 9
  • If tempScale is \"C\", convert each temperature from Celsius to Fahrenheit using the formula: F = (C * 9 / 5) + 32

The converted temperatures should replace the original values in the temps list at their respective index positions. The function should return the updated temps list.


Sample Output


Example 1: Converting Fahrenheit to Celsiustemps_list = [32, 100, 212] converted_temps = convertTemp(temps_list, \"F\") print(converted_temps)

Output:

[0.0, 37.77777777777778, 100.0]
Example 2: Converting Celsius to Fahrenheittemps_list = [0, 37.78, 100] converted_temps = convertTemp(temps_list, \"C\") print(converted_temps)

Output:

[32.0, 100.00399999999999, 212.0]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Python Code for Temperature Conversion def convertTemptemps tempScale Check the temperature scale provided if tempScale F Convert each Fahrenheit temp... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!