Lecture

Coding Quiz - Python Temperature Converter

In this coding quiz, you will write a function to convert temperatures between Celsius (C) and Fahrenheit (F).

The function should be able to take a temperature in Celsius and convert it to Fahrenheit, or take a temperature in Fahrenheit and convert it to Celsius.

Parameter Format
def solution(temperature, scale): # Write your code here return # Write your return value here
  • temperature is the parameter representing the temperature to be converted.

  • scale will have one of the values C (Celsius) or F (Fahrenheit).

  • Using conditional statements, if scale is C, convert from Celsius to Fahrenheit, and if scale is F, convert from Fahrenheit to Celsius.


Constraints

  • The input temperature can be in integer or floating-point form.

  • Use the following formulas for conversion between Celsius and Fahrenheit:

    • Celsius to Fahrenheit: (Celsius temperature × 9/5) + 32
    • Fahrenheit to Celsius: (Fahrenheit temperature - 32) × 5/9

Input/Output Examples

  • Input: Celsius 25, Output: Fahrenheit 77

  • Input: Fahrenheit 77, Output: Celsius 25

Lecture

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help