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.
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
Lessons in this chapter · Control Logical Flow with if, else, and elif
- 1. Controlling Program Flow with if Statements
- 2. The else Statement for When if Condition is False
- 3. Executing When One of Multiple Conditions is Met Using the elif Statement
- 4. Multiple-choice quiz
- 5. Which values are always considered False?
- 6. The `pass` Keyword That Does Nothing
- 7. Indicating Unimplemented Features with NotImplementedError
- 8. Coding Quiz - Python Temperature Converter
- 9. Multiple-choice quiz
- 10. Fill-in-the-blank quiz
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help