Coding Quiz - Python Temperature Converter
This coding quiz involves writing a function to convert temperatures between Celsius(C)
and Fahrenheit(F)
.
The solution function should 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
-
temperature
is the parameter representing the temperature you want to convert. -
scale
takes one of two values: C (Celsius) or F (Fahrenheit). -
Use conditional statements to write code that converts Celsius to Fahrenheit when
scale
is C, and Fahrenheit to Celsius whenscale
is F.
Constraints
-
The input temperature should be either an integer or a float.
-
Use the following formulas for conversion between Celsius and Fahrenheit:
- From Celsius to Fahrenheit:
(Celsius temperature × 9/5) + 32
- From Fahrenheit to Celsius:
(Fahrenheit temperature - 32) × 5/9
- From Celsius to Fahrenheit:
Example Input and Output
-
Input: Celsius
25
, Output: Fahrenheit77
-
Input: Fahrenheit
77
, Output: Celsius25
When writing a function in Python to convert Celsius (C) to Fahrenheit (F), what is the formula for converting Celsius to Fahrenheit?
(Celsius temperature × 5/9) + 32
(Celsius temperature × 9/5) - 32
(Celsius temperature × 9/5) + 32
(Celsius temperature - 32) × 5/9
Lecture
AI Tutor
Publish
Design
Upload
Notes
Favorites
Help