Answered step by step
Verified Expert Solution
Link Copied!

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:

  1. 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]).
  2. Within the function, incorporate an IF/ELIF statement to evaluate the temperature scale entered ("C" or "F").
  3. 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.
  4. 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.
  5. Prompt the user to enter a temperature value and scale. Store the input in variables (i.e., tempEntered, tempScale).
  6. Def and initialize the temps list to hold two number values.
  7. 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.)
  8. Call temperature conversion function passing it the temperature values in a list and a letter code for temperature scale.
  9. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions