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.
def solution(temperature, scale): # Write your code here return # Write your return value here
-
temperatureis the parameter representing the temperature to be converted. -
scalewill have one of the values C (Celsius) or F (Fahrenheit). -
Using conditional statements, if
scaleis C, convert from Celsius to Fahrenheit, and ifscaleis 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: Fahrenheit77 -
Input: Fahrenheit
77, Output: Celsius25
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help