Coding Quiz - Python Temperature Converter
This coding quiz involves writing a function to convert temperatures between Celsius(C) and Fahrenheit(F).
The function should convert a temperature from Celsius to Fahrenheit or from Fahrenheit to Celsius based on the provided scale.
Function Signature
def solution(temperature, scale):
# Write your code here
return # Write your return value here
-
temperatureis the parameter representing the temperature you want to convert. -
scaletakes one of two values: C (Celsius) or F (Fahrenheit). -
Use conditional statements to write code that converts Celsius to Fahrenheit when
scaleis C and Fahrenheit to Celsius whenscaleis 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.