Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am trying to code a python program that requests a temperature value and the temperature scale used by the user with the following Input:
I am trying to code a python program that requests a temperature value and the temperature scale used by the user with the following Input:
- Use the def keyword to define a temperature conversion function (i.e., convertTemp) that accepts two parameters (a temperatures list and a temperature scale letter value [i.e., temps, tempScale]).
- Within the function, incorporate an IF/ELIF statement to evaluate the temperature scale entered ("C" or "F").
- When the temperature scale entered is F, incorporate a formula to calculate the Celsius equivalent and place the result in the appropriate index position in the temps list. See conversion formula above in requirements.
- When the temperature scale entered is C, incorporate a formula to calculate the Fahrenheit equivalent and place the result in the appropriate index position in the temps list. See conversion formula above in requirements.
- Prompt the user to enter a temperature value and scale. Store the input in variables (i.e., tempEntered, tempScale).
- Def and initialize the temps list to hold two number values.
- Incorporate an IF/ELIF statement to evaluate the temperature scale entered and populate the appropriate list position (index) with the temperature value entered. (i.e., Use position zero for Celsius and position one for Fahrenheit.)
- Call temperature conversion function passing it the temperature values in a list and a letter code for temperature scale.
- Print the results from the temperature conversion function. Display the temperature value entered (i.e., 32 F) and then display the temperature in both Celsius and Fahrenheit.
Okay...So, my code is below. I am doing something wrong and I don't know what. I need to see what the code should resemble to get the output shown after my code.
def convert_temp(scale=None, source_temp=None): if (scale == "F") or (scale == "f"): return 'C', (source_temp - 32.0) * (5.0/9.0) elif (scale == "C") or (scale == "c"): return 'F', (source_temp * (9.0/5.0)) + 32.0 else: print("Needs to be (F) or (C)!") scale = input("Select (F) or (C): " ) source_temp = int(input("What is the temperature: " )) s, m = convert_temp(scale, source_temp) print(source_temp, "degrees", scale.title(), "is", m, "degrees", s)
Expected output:
Enter a temperature value:32
Enter a single letter to indicate the temperature scale (C or F):F
You entered32.0degreesF >>>
The temperature in Celsius is0.0
The temperature in Fahrenheit is32.0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started