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.
Function Signature
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 to convert 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
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.