Purpose

In this assignment, you will create a user-defined function passing variables both by value and by reference and using arguments of different data types.

Assignment Requirements

For this project, you will write a program that requests a temperature value and the temperature scale used from the user. Write a single function that evaluates a given temperature and returns associated conversions. For example, the user could input a temperature value in Fahrenheit and receive the temperature in its Celsius equivalent.

For this project, you will write a program that requests a temperature value and the temperature scale used from the user. Write a single function that evaluates a given temperature and returns associated conversions. For example, the user could input a temperature value in Fahrenheit and receive the temperature in its Celsius equivalent.

Conversion formulas for your reference:

F = (C * 9/5) + 32
C = (F - 32) * 5/9

Assignment Instructions

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]).

Reference: Refer to Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 4: Definition of a Function / Returning More Than One Value; and Programming in Python, Chapter 6: Python Functions / Pass by Value vs. Pass by Reference.

2. Reference: Refer to Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 4: Definition of a Function / Returning More Than One Value; and Programming in Python, Chapter 6: Python Functions / Pass by Value vs. Pass by Reference.

  • 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.
  • Return temps list.

Reference: Refer to Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 2: Simple Math / Order of Operations; Chapter 4: Definition of a Function / Returning More Than One Value; and Chapter 5: The if Statement / Comparison Operators; and Programming in Python, Chapter 6: Python Functions / Pass by Value vs. Pass by Reference.

3. Reference: Refer to Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 2: Simple Math / Order of Operations; Chapter 4: Definition of a Function / Returning More Than One Value; and Chapter 5: The if Statement / Comparison Operators; and Programming in Python, Chapter 6: Python Functions / Pass by Value vs. Pass by Reference.

Example prompts:

Enter a temperature value:
Enter a single letter to indicate the temperature scale (C or F):

Hint: Placing float ahead of the input statement will store the user input as a decimal number data type. Since the temperature value will be used in the conversion calculation, you will want this to be a numeric value. You may incorporate additional optional data validation as you wish.

Reference: Refer back to your Unit 1 and 3 readings in Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 3: Built-In Functions / Getting Input From the User.

4. Define and initialize your temps list to hold two number values

Hint: Initialize both positions to zero for now. The user will only be entering one temperature value, so you will have to fill in one position in the list with that value and leave the other as zero to be converted when the function is called.

Reference: Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 7: Lists.

5. eference: Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 7: Lists.

Example:

if tempScale == "C":
temps[0] = tempEntered

6. Call your temperature conversion function passing it the temperature values in a list and a letter code for temperature scale.

Reference: Refer to Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 4: Calling a User-Defined Function.

7. Reference: Refer to Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 4: Calling a User-Defined Function.

Reference: Learn to Program With Python 3: A Step-by-Step Guide to Programming, 2nd edition, Chapter 2: Print Statements.

EXPECTED OUTPUT:

Enter a temperature value: 32
Enter a single letter to indicate the temperature scale (C or F): F
You entered 32.0 degrees F >>>
The temperature in Celsius is 0.0
The temperature in Fahrenheit is 32.0
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.